We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
//function that partitions array based on the condition
static void partition(int[] ar) {
int temp=0;
int pivot=ar[0];
int pIndex=ar.length-1;
for(int i=ar.length-1;i>=1;i--){
if(ar[i]>=pivot){
temp=ar[i];
ar[i]=ar[pIndex];
ar[pIndex]=temp;
pIndex-=1;
}
}
temp=ar[pIndex];
ar[pIndex]=ar[0];
ar[0]=temp;
printArray(ar);
}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Quicksort 1 - Partition
You are viewing a single comment's thread. Return to all comments →
This worked for me!!(JAVA)