</pre><pre code_snippet_id="1864735" snippet_file_name="blog_20160903_2_5420694" name="code" class="cpp">void sort1(int a[], int first, int last){
if (first< last){
int i = first;
int j = last;
int x = a[i];
while(i < j){
while (a[j] > x) j--;
if (first < last){
a[i] = a[j];
i++;
}
while (a[i] < x) i++;
if (first < last){
a[j] = a[i];
j--;
}
}//while
a[i] = x;
sort1(a, first, i-1);
sort1(a, i+1, last);
}//if
}
int partation(int a[], int first, int last)
{
if (first < last){
int j = first-1;
for (int i=first; i<last; i++)
{
if (a[i] < a[last]){
j++;
int tmp = a[i];
a[i] = a[j];
a[j] = tmp;
}
}//while
j++;
int tmp = a[last];
a[last] = a[j];
a[j] = tmp;
return j;
}
}
void sort2(int a[], int first, int last)
{
if (first < last){
int pos = partation(a, first, last);
sort2(a, first, pos-1);
sort2(a, pos+1, last);
}
}