Question
Can you help me see what I am doing wrong in my code? public static int partition( int [] arr, int l, int r) {
Can you help me see what I am doing wrong in my code?
public static int partition(int [] arr, int l, int r)
{
int n = arr.length;
int [] left = new int [ (n+1)/2];
int [] right = new int [n - left.length];
l = left.length;
r = right.length;
int p = arr[l];
int i = l + 1;
int temp;
for(int j = l+1 ;j { if(arr[j] { temp = a[j]; arr[j] = arr[i]; arr[i] = temp; i++; } temp = arr[l]; arr[l] = arr[i-1]; arr[i-1] = temp; } return (i-1); // report final pivot position } public static int quickSort (int [] arr, int l, int r) { int n = arr.length; int [] left = new int [ (n+1)/2]; int [] right = new int [n - left.length]; l = left.length; r = right.length; if (l >= r) // 0- or 1-element subarray { return 0; } int i = choose(arr,l,r); int temp = arr[l]; // make pivot first arr[l] = arr[i]; arr[i] = temp; int j = partition(arr,l,r); int c = quickSort(arr, l, j-1); int d = quickSort(arr, j+1, r); } public static int choose (int []arr, int l, int r) { return l; } public static void main(String[] arg) { int [] a = {2148,9058,7742,3153,6324,609, 7628,5469,7017,504 }; int n = a.length; int [] left = new int [ (n+1)/2]; int [] right = new int [n - left.length]; int l = left.length; int r = right.length; int result = quickSort (a, 0, n); System.out.println(result); }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started