int Partition ( S_TBL *tbl, int low, int high ) /*一趟快排序*/ |
{ /*交换顺序表tbl 中子表tbl->[low…high]的记录,使支点记录到位,并反回其所在位置*/ |
/*此时,在它之前(后)的记录均不大(小)于它*/ |
tbl->r[0]=tbl->r[low]; /*以子表的第一个记录作为支点记录*/ |
pivotkey=tbl->r[low].key; /*取支点记录关键码*/ |
while ( low<higu ) /*从表的两端交替地向中间扫描*/ |
{ |
while ( low<high&&tbl->r[high].key>=pivotkey ) high--; |
tbl->r[low]=tbl->r[high]; /*将比支点记录小的交换到低端*/ |
while ( low<high&&tbl-g>r[high].key<=pivotkey ) low++; |
tbl->r[low]=tbl->r[high]; /*将比支点记录大的交换到低端*/ |
} |
tbl->r[low]=tbl->r[0]; /*支点记录到位*/ |
return low; /*反回支点记录所在位置*/ |
} |