Advertisement
Guest User

Untitled

a guest
May 28th, 2015
225
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.67 KB | None | 0 0
  1. int partition(int *tab, int firstIndex, int lastIndex){
  2. int pivot = tab[lastIndex];
  3. int indexI = firstIndex;
  4. int indexJ = firstIndex;
  5.  
  6. while(indexI < lastIndex){
  7. if(pivot <= tab[indexI]){
  8. indexI++;
  9. }else{
  10. swap(tab[indexI],tab[indexJ]);
  11. indexJ++;
  12. indexI++;
  13. }
  14. }
  15. swap(tab[lastIndex],tab[indexJ]);
  16. return indexJ;
  17. }
  18.  
  19. void LomutoQuick(int *tab, int firstIndex, int lastIndex){
  20. if(firstIndex < lastIndex){
  21. int pivot = partition(tab, firstIndex, lastIndex);
  22. LomutoQuick(tab, firstIndex, pivot -1);
  23. LomutoQuick(tab, pivot + 1, lastIndex);
  24. }
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement