Quick Sort C++

using namespace std;
void cetak(int *array,int length) //print array elements
int i=0;
cout<<array[i] << " " ;
cout <array[j]);

} while (x <array[i]);

if (i < j)
temp = array[i];
array[i] = array[j];
array[j] = temp;
}while (i < j);
return j; // returns middle subscript

void quickSort(int *num, int top, int bottom)
// top = subscript of beginning of array
// bottom = subscript of end of array

int middle;
if (top < bottom)
middle = partisi(num, top, bottom);
quickSort(num, top, middle); // sort first section
quickSort(num, middle+1, bottom); // sort second section

int main()
int a[]={9,6,5,23,2,66,14,8,2,7,1,8}; // array to sort
cetak(a,12); // print elements
quickSort(a,0,12); //call to bubble sort
cetak(a,12); // print elements
return 0;


4 thoughts on “Quick Sort C++

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s