Quick sort algorithm, with ascending order as an example
Operating system: Ubuntu
Compiling software: GCC
Results screenshot:
Source:
#include <stdio.h> void quickSort (int *,int,int);
int findposs (int *,int,int);
int main () {int i;
int arry[] = {8,9,0,-3,6,7,-11};
QuickSort (arry,0,6);
printf ("After sorted:\n");
for (i=0;i<7;i++) printf ("%d", arry[i]);
printf ("\ n");
return 0;
}//Quick sort function to implement void QuickSort (int *a,int low,int high) {int pos by recursion;
if (Low < high) {pos = Findposs (A,low,high);
QuickSort (A,LOW,POS-1);
QuickSort (A,pos+1,high);
} return; //The function returns the location of the value of the split point, A is the first address of the array to be sorted, and low just begins to represent the position of the first element within the sort range, gradually moving to the right, and high is just beginning to represent the last position within the sort range and moving the int fin
Dposs (int *a,int low,int high) {int val = A[low];
While [low < High] {while (low=val) high--;
A[low] = A[high];
while (Low<=val) low++;
A[high] = A[low];
}//At this time Low=high a[low] = val;
return to Low; }
Back to the column page: http://www.bianceng.cnhttp://www.bianceng.cn/Programming/sjjg/
Author: csdn Blog Lan pavilion Wind and Rain