Posted By

sleepyizme on 02/16/12


Tagged


Versions (?)

quickSort


 / Published in: Java
 

partition & quickSort

  1. public static int partition(int[] a, int f, int b) {
  2. int pivot = a[f];
  3. while (f < b) {
  4. while (f < b && a[b] >= pivot) {
  5. b--;
  6. }
  7. while (f < b && a[f] < pivot) {
  8. f++;
  9. }
  10. if (f < b) {
  11. int tmpB = a[b];
  12. a[b] = a[f];
  13. a[f] = tmpB;
  14. }
  15. }
  16. return b;
  17. }
  18.  
  19.  
  20. public static void quickSort(int[] a, int f, int b) {
  21. if (f < b) {
  22. int division = partition(a, f, b);
  23. quickSort(a, f, division);
  24. quickSort(a, division + 1, b);
  25. }
  26. }

Report this snippet  

You need to login to post a comment.