本文仅用作学习记录,大神勿喷O(∩_∩)O~
代码一、百度百科C++语言版本代码,参考数据结构p274(清华大学出版社,严蔚敏)
1 void Qsort1(int a[], int low, int high)//百度百科C++语言版本代码 2 {/*参考数据结构p274(清华大学出版社,严蔚敏)*/ 3 if(low >= high) return; 4 int first = low; 5 int last = high; 6 int key = a[first];/*用字表的第一个记录作为枢轴*/ 7 8 while(first < last) 9 { 10 while(first < last && a[last] >= key) 11 { 12 --last; 13 } 14 a[first] = a[last];/*将比第一个小的移到低端*/ 15 while(first < last && a[first] <= key) 16 { 17 ++first; 18 } 19 a[last] = a[first]; 20 /*将比第一个大的移到高端*/ 21 } 22 a[first] = key;/*枢轴记录到位*/ 23 Qsort1(a, low, first-1); 24 Qsort1(a, first+1, high); 25 }