// Online C++ compiler to run C++ program online
#include <iostream>
using namespace std;
int Partition(int *A, int start, int end)
{
int pivot = A[end];
int partitionIndex = start;
for(int i =start; i < end; i++)
{
if(A[i]<= pivot)
{
swap(A[i], A[partitionIndex]);
partitionIndex++;
}
}
swap(A[partitionIndex], A[end]);
return partitionIndex;
}
void QuickSort(int *A, int start, int end)
{
if(start < end)
{
int pertitionIndex = Partition(A, start, end);
QuickSort(A, start, pertitionIndex-1);
QuickSort(A, pertitionIndex+1, end);
}
}
int main() {
int A[] = {7,6,5,4,3,2,1,0};
QuickSort(A, 0, 7);
for (int i = 0; i<8; i++) cout<<A[i]<<" ";
return 0;
}
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter