快速排序 int Partition(RcdType R[],int low,int high){ R[0]R[low]; ∥将枢轴记录移至数组的闲置分量 pivotkey=Rlow.key;I∥枢轴记录关键字 while(low<high){∥从表的两端交替地向中间扫描 while(low<high&&R[high].key>=pivotkey) --high; R[low++]=R[high]; ∥将比枢轴记录小的记录移到低端 while (low<high&&R[low].key<=pivotkey) ++loW; R[high--]R[low]; ∥将比枢轴记录大的记录移到高端 }//while R[low]R[O]; ∥枢轴记录移到正确位置 return low; ∥返回枢轴位置 }l∥Partition
快速排序 int Partition ( RcdType R[], int low, int high) { R[0] = R[low]; // 将枢轴记录移至数组的闲置分量 pivotkey = R[low].key; // 枢轴记录关键字 while (low<high) { // 从表的两端交替地向中间扫描 while(low<high&& R[high].key>=pivotkey) --high; R[low++] = R[high]; // 将比枢轴记录小的记录移到低端 while (low<high && R[low].key<=pivotkey) ++low; R[high--] = R[low]; // 将比枢轴记录大的记录移到高端 } //while R[low] = R[0]; // 枢轴记录移到正确位置 return low; // 返回枢轴位置 } // Partition
快速排序 void QSort(RedType R[],int s,int t){ ∥对记录序列R[s.t进行快速排序 if(s<t-1){ 川长度大于1 pivotloc Partition(R,s,t);//R[s..t] QSort(R,s,pivotloc-1); 川对低子序列递归排序 QSort(R,pivotloc+1,t); 川对高子序列递归排序 if }/Qsort void QuickSort(SqList L){ QSort(L.r,1,L.length); }∥QuickSort
快速排序 void QSort (RedType R[], int s, int t ) { // 对记录序列R[s..t]进行快速排序 if (s < t-1) { // 长度大于1 pivotloc = Partition(R, s, t);// 对 R[s..t] QSort(R, s, pivotloc-1); // 对低子序列递归排序 QSort(R, pivotloc+1, t); // 对高子序列递归排序 } // if } // Qsort void QuickSort( SqList & L) { QSort(L.r, 1, L.length); } // QuickSort