Advertisement
skilletwaffles

quickSort

Feb 27th, 2015
205
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.81 KB | None | 0 0
  1. int g = first, h = last;
  2. int midIndex = (first + last) / 2;
  3. int dividingValue = list[midIndex];
  4. steps +=5;
  5. do
  6. {
  7. while (list[g] < dividingValue){ g++; steps +=1;}
  8. while (list[h] > dividingValue){ h--; steps +=1;}
  9. steps +=2;
  10. if (g <= h)
  11. {
  12. //swap(list[g], list[h]);
  13. int temp = list[g];
  14. list[g] = list[h];
  15. list[h] = temp;
  16. g++;
  17. h--;
  18. steps +=6;
  19. }
  20. }
  21. while (g < h);
  22. if (h > first){
  23. quickSort (list,first,h);
  24. steps++;
  25. }
  26. if (g < last){
  27. quickSort (list,g,last);
  28. steps++;
  29. }
  30. steps +=2;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement