二分查找
int search_bin(SSTable ST, KeyType key){ low = l; high = ST.length; while (low <= high) { mid = (low + high) / 2; if(EQ(key, ST.elem[mid].key)) return mid; else if (LT(key, ST.elem[mid].key)) high = mid - 1; else low = mid + 1; } return 0; }
快速排序
void qsort(SqList &L, int low, int high){ if(low < high){ pivotloc = partition(L, low, high); qsort(L, low, pivotloc - 1); qsort(L, pivotloc + 1, high); } } 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]; } L.r[low] = L.r[0]; return low; }
希尔排序
void shellSort(SqList &L, int dlta[], int t){ for (k = 0; k < t; ++k) { shellInsert(L, dlta[k]); } } void shellInsert(SqList &L, int dk){ for (i = dk + 1; i < L.length ; ++i) { if (LT(L.r[i].key, L.[i - dk].key)) { L.r[0] = L.r[i]; for(j = i - dk; j > 0 && LT(L.r[0].key, L.r[j].key); j -= dk) L.r[j + dk] = L.r[j]; L.r[j + dk] = L.r[0]; } } }