#include <iostream>
using namespace Std;
void swap (int array[], int index1, int index2) {
int t = array[index1];
ARRAY[INDEX1] = Array[index2];
ARRAY[INDEX2] = t;
Return
}
int partition (int array[], int beginpos, int endpos)
{
int comparedval = Array[beginpos];
int cursorfrombegin = Beginpos + 1;
int cursorfromend = Endpos;
while (true) {
while (Array[cursorfrombegin] < comparedval) {cursorfrombegin++;}
while (Array[cursorfromend] > Comparedval) {cursorfromend--;}
if (cursorfrombegin>=cursorfromend) {break;}
Swap (array, cursorfrombegin, cursorfromend);
}
Swap (ARRAY,CURSORFROMEND,BEGINPOS);
return cursorfromend;
}
void QuickSort (int array[],int begin,int end) {
if (begin >= end) {Cout<<begin<<end<<endl;return;}
int k = partition (Array,begin,end);
QuickSort (array, begin,k-1);
QuickSort (array, k+1, end);
}
int main () {
int array[6]={3,5,9,8,7,5};
QuickSort (Array, 0, 5);
for (int i =0;i<6;i++) {Cout<<array[i]<<endl;}
}
Division and Recursion-quicksort