I attempted to write a quicksort implementation after watching this video on youtube. https://www.youtube.com/watch?v=MZaf_9IZCrc&t=215s but it does not work. Can someone tell me what I am doing wrong? Thank you Ferda
public class Trial{
public static void main(String []args){
int arr[] = {7, 3, 4, 2, 6, 1, 5};
quickSort(arr, 0, 6);
}
public static void quickSort(int[] arrInput, int start, int end){
int arr[] = new int[end-start+1];
for(int i=start, j=0; i<end; i++, j++){
arr[j]=arrInput[i];
}
int size = arr.length;
int pivotValue = arr[size-1];
for (int i=-1; i<arr.length; i++){
for(int j=0; j<arr.length; j++){
if(arr[j]< pivotValue){
int temp = arr[j];
i++;
arr[j] = arr[i];
arr[i] = temp;
}
for(int p = i; p< size-2; p++ ){
arr[p+1] = arr[p];
}
arr[i] = pivotValue;
quickSort(arr, 0, i);
quickSort(arr, i+1, size-1);
}
}
}
}
Quicksort is something like that:
After that, you can use your video to implement partition method