@@ -62,6 +62,31 @@ function swap(arr, i, j) {
6262 arr[i] = arr[j];
6363 arr[j] = temp;
6464}
65+ functiion paritition2 (arr , low , high ) {
66+ let pivot = arr[low];
67+ while (low < high) {
68+ while (low < high && arr[high] > pivot) {
69+ -- high;
70+ }
71+ arr[low] = arr[high];
72+ while (low < high && arr[low] <= pivot) {
73+ ++ low;
74+ }
75+ arr[high] = arr[low];
76+ }
77+ arr[low] = pivot;
78+ return low;
79+ }
80+
81+ function quickSort2 (arr , low , high ) {
82+ if (low < high) {
83+ let pivot = paritition2 (arr, low, high);
84+ quickSort2 (arr, low, pivot - 1 );
85+ quickSort2 (arr, pivot + 1 , high);
86+ }
87+ return arr;
88+ }
89+
6590```
6691
6792
@@ -127,3 +152,34 @@ func swap(arr []int, i, j int) {
127152arr[i], arr[j] = arr[j], arr[i]
128153}
129154```
155+
156+ ## 6. C++版
157+
158+
159+ ``` C++
160+ // 严蔚敏《数据结构》标准分割函数
161+ Paritition1 (int A[ ] , int low, int high) {
162+ int pivot = A[ low] ;
163+ while (low < high) {
164+ while (low < high && A[ high] >= pivot) {
165+ --high;
166+ }
167+ A[ low] = A[ high] ;
168+ while (low < high && A[ low] <= pivot) {
169+ ++low;
170+ }
171+ A[ high] = A[ low] ;
172+ }
173+ A[ low] = pivot;
174+ return low;
175+ }
176+
177+ void QuickSort(int A[ ] , int low, int high) //快排母函数
178+ {
179+ if (low < high) {
180+ int pivot = Paritition1(A, low, high);
181+ QuickSort(A, low, pivot - 1);
182+ QuickSort(A, pivot + 1, high);
183+ }
184+ }
185+ ```
0 commit comments