Well, your printArray()
looks OK, but one thing stands out right away:
The initial parameters you are passing to quickSort()
are incorrect. You have:
int[] a = new int[20];
...
int left = a[0];
int right = a[19];
...
quickSort(a, left, right);
You are initializing left
and right
to 0
, and thus you end up calling quickSort(a, 0, 0)
(not what you want). You probably mean to do this instead, as left
and right
hold the index:
int left = 0;
int right = 19;
Or simply:
quickSort(a, 0, 19);
As for your mergeSort()
, the implementation is simply incomplete. It appears you have implemented the "merge" operation (an essential piece of the algorithm), but not the "merge sort" overall algorithm. You may want to check out Mergesort in Java (for examples) or Merge Sort (for general overview).
By the way, you may wish to specify a.length - 1
instead of 19
, that way you can change the size of a
without having to modify other code (same would go for the 9
you pass to mergeSort()
, but that is moot as you will see it is unnecessary once you implement the algorithm fully).