Advertisement
Buffet_Time

Untitled

Apr 6th, 2016
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.58 KB | None | 0 0
  1. package Three;
  2.  
  3. /**
  4. * Created by Daniel on 4/6/2016.
  5. */
  6.  
  7. /*
  8. * To change this license header, choose License Headers in Project Properties.
  9. * To change this template file, choose Tools | Templates
  10. * and open the template in the editor.
  11. */
  12.  
  13.  
  14. /**
  15. *
  16. * @author David
  17. */
  18. public class SortableArrayListWithQuickSort<T extends Comparable<T>> extends SortableArrayListWithStack {
  19. @Override
  20. protected void sortSubArray(
  21. int[] arr, int low, int high)
  22. {
  23.  
  24.  
  25.  
  26. if (arr == null || arr.length == 0) {
  27. return;
  28. }
  29.  
  30. if (low >= high) {
  31. return;
  32. }
  33.  
  34. // pick the pivot
  35. int middle = low + (high - low) / 2;
  36. int pivot = arr[middle];
  37.  
  38. // make left < pivot and right > pivot
  39. int i = low, j = high;
  40. while (i <= j) {
  41. while (arr[i] < pivot) {
  42. i++;
  43. }
  44.  
  45. while (arr[j] > pivot) {
  46. j--;
  47. }
  48.  
  49. if (i <= j) {
  50. int temp = arr[i];
  51. arr[i] = arr[j];
  52. arr[j] = temp;
  53. i++;
  54. j--;
  55. }
  56. }
  57.  
  58. // recursively sort two sub parts
  59. if (low < j) {
  60. sortSubArray(arr, low, j);
  61. }
  62.  
  63. if (high > i) {
  64. sortSubArray(arr, i, high);
  65. }
  66. }
  67.  
  68. private void quickSort(int[] arr, int low, int j) {
  69. }
  70.  
  71. @Override
  72. protected void sortSubArray(Comparable[] listItems, int lowIndex, int highIndex) {
  73.  
  74. }
  75. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement