well i have 2 weeks reading and testing some C++ but unfortunately i fell into a wall.
I succeed making an array with random length and random elements (yeah i did it)and i want to help me making those elements sorted. eg quicksort
I read "algorithms in C++ " written by SEDGEWICK and here his proposal
template<class Item>
void quicksort(Item a[],int l,int r)
{
if (r<=l) return;
int m=partition(a,l,r);
quicksort(a,l,m-1);
quicksort(a,m+1,r);
}
template<class Item>
int partition(Item a[],int l, int r)
{
int m=l-1, j=r; Item v=a[r];
for(;;)
{
while(a[++m]<v);
while(v<a[--j]) if (j==1) break;
if(m>=j)break;
exch(a[m],a[j]);
}
exch(a[m],a[r]);
return m;
}
1st --How do i declare quicksort and partition in my main function. I tried to copy paste it (i know its wrong) and compile it but no luck
2nd--in the code above "a" will be my arrays name instead?
thanks
I'm looking forward to hearing from you