Guest User

Untitled

a guest
Mar 24th, 2016
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.39 KB | None | 0 0
  1. int index1 = left + 1;
  2.     int index2 = right;
  3.     int equal_left = left + 1;
  4.     int equal_right = right;
  5.  
  6.     int pivot = t[left];
  7.  
  8.     while( index1 <= index2)
  9.     {
  10.         while( index1 < index2 && t[index1] < pivot)
  11.             ++index1;
  12.  
  13.         while( t[index2] > pivot)
  14.             --index2;
  15.  
  16.         if( index1 == index2 && pivot == t[index1]) // wstawiamy t[index1] na pozycje equal z lewej
  17.         {
  18.             SWAP(t[index1],t[equal_left],int);
  19.             ++equal_left;
  20.             break;
  21.         }
  22.  
  23.         if( index1 >= index2) // nie ma nic do roboty, konczymy
  24.             break;
  25.  
  26.         SWAP(t[index1],t[index2],int);
  27.  
  28.         if( t[index1] == pivot) // wstaw na pozycje equal z lewej
  29.         {
  30.             SWAP(t[index1],t[equal_left],int);
  31.             ++equal_left;
  32.         }
  33.  
  34.         if( t[index2] == pivot) // wstaw na pozycje equal  z prawej
  35.         {
  36.             SWAP(t[index2],t[equal_right],int);
  37.             --equal_right;
  38.         }
  39.  
  40.         ++index1;
  41.         --index2;
  42.  
  43.     }
  44.  
  45.     //wstawiamy rowne klucze na wlasciwe miejsce
  46.     index1 = index2 + 1;
  47.     int i;
  48.  
  49.     for(i = left + 1; i < equal_left; ++i )
  50.     {
  51.         SWAP(t[i],t[index2],int);
  52.         --index2;
  53.     }
  54.  
  55.     for(i = right; i > equal_right; --i)
  56.     {
  57.          SWAP(t[i],t[index1],int);
  58.           ++index1;
  59.     }
  60.  
  61.     SWAP(t[index2],t[left],int);
  62.  
  63.     return index2;
  64. }
Advertisement
Add Comment
Please, Sign In to add comment