I have a problem with this code :
#include<iostream>
using namespace std;
void qsort(int A[], int len)
{
if(len>=2){
int l=0;
int u=len-1;
int pivot=A[rand()%len];
while(l<u)
{
while(A[l]<pivot)l++;
while(A[u]>pivot)u--;
swap(A[l], A[u]);
}
qsort(A,l);
qsort(&A[l+1],len-l-1);
}
else{return;}
}
void swap(int a, int b)
{
int temp;
temp=a;
a=b;
b=temp;
}
void printlist(int l[],int len)
{
int i;
for(i=0;i<len;i++)
{
cout<<l[i]<<endl;
}
}
int main(int argc, char *argv[])
{
int list[12]={333,250,323,12,9,900,0,732,56,88,72,12};
printlist(list,12);
cout<<endl;
qsort(list,12);
printlist(list,12);
return 0;
}
It’s working well if the element of array <=11, if more than 11 the program will crash, can anybody find the problem..
Sorry for my horrible english...