#include <iostream>using namespace std;void grial (int a[],int x,int y) {if (x>=y) return; int I=x;int J=y;int temp; int key=a[(I+J)/2];while (i<j) {while (A[i]<key) i++;//finds the first number larger than key while (A[j]>key) j--;//finds the first number smaller than key if (i <=J) {temp=a[i];a[i]=a[j];a[j]=temp;i++;j--;}} When the i<j, the smaller than the key and larger than key exchange, until i>j, determined the median, less than or equal to J of the array divided to the left of the smaller group, greater than or equal to the division to the right of the larger group,//The array is divided into 2 parts, and then respectively recursive comparison. finally when x< Y jumps out of recursion. Grial (A,X,J); Grial (a,i,y);} int main () {int a[]={2,3,1,94,53,3,0}; Grial (a,0,6); for (int i=0;i<7;i++) {cout<<a[i]<< " ";} Cout<<endl;return 0;}
C + + Quick sort (with intermediate elements as a meta point)