
Code: C++
#include <iostream.h>
#include <stdlib.h>
void quicksort ( int array[], int lo, int hi );
int main()
{
int array[7, 9, 15, 14, 11, 13, 4, 3, 21, 33, 28];
cout<<quicksort(array[]);//parse error before ] what am i doing wrong? :(
system("PAUSE");
return 0;
}
void quicksort ( int array[], int lo, int hi )
{
// lo is the lower index,
// hi is the upper index
int i = lo, j = hi, temp;
//step 1: x will be the pivot
int x = array[(lo+hi)/2];
//step 2: partition
do
{
while(array[i]<x)
i++;
while(array[j]>x)
j--;
if (i<=j)
{
temp = array[i]; //swap
array[i] = array[j];
array[j] = temp;
i++;
j-- ;
}
}
while(i<=j);
//step 3: recursion
if (lo<j) quicksort(array,lo,j);
if (i<hi) quicksort(array,i,hi);
//cout<<array[i]<<" ";
}


