Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int partition(int *tab, int firstIndex, int lastIndex){
- int pivot = tab[lastIndex];
- int indexI = firstIndex;
- int indexJ = firstIndex;
- while(indexI < lastIndex){
- if(pivot <= tab[indexI]){
- indexI++;
- }else{
- swap(tab[indexI],tab[indexJ]);
- indexJ++;
- indexI++;
- }
- }
- swap(tab[lastIndex],tab[indexJ]);
- return indexJ;
- }
- void LomutoQuick(int *tab, int firstIndex, int lastIndex){
- if(firstIndex < lastIndex){
- int pivot = partition(tab, firstIndex, lastIndex);
- LomutoQuick(tab, firstIndex, pivot -1);
- LomutoQuick(tab, pivot + 1, lastIndex);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement