#include <iostream>
using namespace std;
int split(int a[],int p,int r)
{
int x=a[r];
int i=p-1;int j=r+1;
while(1)
{
do{
i++;
}while(a[i]<=x);
do{
j--;
}while(a[j]>=x);
if(i<j)
{
int temp=a[i];
a[i]=a[j];
a[j]=temp;
}
else{
return j;
}
}
}
int* quicksort(int a[],int p,int r)
{
if(p<r)
{
int q=split(a,p,r);
quicksort(a,p,q);
quicksort(a,q+1,r);
}
else{
return a;}
}
int main()
{
int a[50],s;
cout<<"enter num of elemenst\n";
cin>>s;
cout<<"enetr "<<s<<" elemets\n";
for(int i=0;i<s;i++)
{cin>>a[i];}
cout<<"\nbefore sorting\n";
for(int i=0;i<s;i++)
{cout<<a[i]<<"\t";}
int* s_arr= quicksort(a,0,s-1);
for(int i=0;i<s;i++)
cout<<"\t"<<s_arr[i];
return 0;
}
Last edited on
quicksort is called, what does this line look like to you:
int* s_arr= quicksort(a,0,s-1);