pivot= Partition( Llow high),∥进行一趟划分 if(high-pivot>pivot-low) Push(S,{ pivot+ Lhigh};∥把长的子序列边界入栈 high=pvot-l;/短的子序列留待下次排序 else Push(, low, pivot-1)); ow=pivot+1 else if(low<high&& high-low<3y/如果当前子序列长度小于3且尚未排好序 Easy Sort(L, low high),∥直接进行比较排序 low=high,∥当前子序列标志为已排好序 else∥如果当前子序列已排好序但栈中还有未排序的子序列 Pop(S,a),∥从栈中取出一个子序列 low=a low high=a high i//while i//QSort NotRecurve int partition( SQLISt&L, int low, int high)/一趟划分的算法,与书上相同 L rOFL r[low]: pivotkey=L rlow]. key while(low <high) while(low<high&&L r[high]. key>=pivotkey) L row=L rhigh while(low<high&&L r[low).key<=pivotkey) low++ L rhigh=L rlow]: y//while L rlow]=Lr[O] return low 3//Partition{ pivot=Partition(L,low,high); //进行一趟划分 if(high-pivot>pivot-low) { Push(S,{pivot+1,high}); //把长的子序列边界入栈 high=pivot-1; //短的子序列留待下次排序 } else { Push(S,{low,pivot-1}); low=pivot+1; } }//if else if(low<high&&high-low<3)//如果当前子序列长度小于 3 且尚未排好序 { Easy_Sort(L,low,high); //直接进行比较排序 low=high; //当前子序列标志为已排好序 } else //如果当前子序列已排好序但栈中还有未排序的子序列 { Pop(S,a); //从栈中取出一个子序列 low=a.low; high=a.high; } }//while }//QSort_NotRecurve int Partition(SQList &L,int low,int high)//一趟划分的算法,与书上相同 { L.r[0]=L.r[low]; pivotkey=L.r[low].key; while(low<high) { while(low<high&&L.r[high].key>=pivotkey) high--; L.r[low]=L.r[high]; while(low<high&&L.r[low].key<=pivotkey) low++; L.r[high]=L.r[low]; }//while L.r[low]=L.r[0]; return low; }//Partition