Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int index1 = left + 1;
- int index2 = right;
- int equal_left = left + 1;
- int equal_right = right;
- int pivot = t[left];
- while( index1 <= index2)
- {
- while( index1 < index2 && t[index1] < pivot)
- ++index1;
- while( t[index2] > pivot)
- --index2;
- if( index1 == index2 && pivot == t[index1]) // wstawiamy t[index1] na pozycje equal z lewej
- {
- SWAP(t[index1],t[equal_left],int);
- ++equal_left;
- break;
- }
- if( index1 >= index2) // nie ma nic do roboty, konczymy
- break;
- SWAP(t[index1],t[index2],int);
- if( t[index1] == pivot) // wstaw na pozycje equal z lewej
- {
- SWAP(t[index1],t[equal_left],int);
- ++equal_left;
- }
- if( t[index2] == pivot) // wstaw na pozycje equal z prawej
- {
- SWAP(t[index2],t[equal_right],int);
- --equal_right;
- }
- ++index1;
- --index2;
- }
- //wstawiamy rowne klucze na wlasciwe miejsce
- index1 = index2 + 1;
- int i;
- for(i = left + 1; i < equal_left; ++i )
- {
- SWAP(t[i],t[index2],int);
- --index2;
- }
- for(i = right; i > equal_right; --i)
- {
- SWAP(t[i],t[index1],int);
- ++index1;
- }
- SWAP(t[index2],t[left],int);
- return index2;
- }
Advertisement
Add Comment
Please, Sign In to add comment