Can u correct my code

it is giving compilation error

#include
using namespace std;

int partition(int arr[],int s,int e) {
int i=s-1;
int j=s;
int pivot=arr[e];

for(j;j<=e-1;j++) {
    if(arr[j]<pivot) {
        i=i+1;
        swap(arr[i],arr[j]);
    }
}

///place pivot at correct position
swap(arr[i+1],arr[e]);
return (i+1);

}

void quickSort(int arr[],int s,int e) {
///base case
if(s>=e) {
return;
}

///recursive calls
int p=partition(arr,s,e);

///left call
quickSort(arr,s,p);

///right call
quickSort(arr,p+1,e);

}

int main() {
int arr[]={2,7,8,6,1,5,4};

int len=sizeof(arr)/sizeof(arr[0]);

quickSort(arr,0,len-1);

for(int i=0;i<len;i++) {
    cout << arr[i] << " ";
}

return 0;

}

@premang
Please save your code at https://ide.codingblocks.com/ and then share link here

@premang
Change line 31 to quickSort(arr,s,p-1);

thank you :slight_smile:

1 Like