1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
| #include <stdio.h> #include <stdlib.h>
#define MAXSIZE 100
#define TURE 1 #define FALSE 0 #define OK 1 #define ERROR 0
#define INFEASIBLE -1
#define OVEREFLOW -2
typedef int Status;
typedef char KeyType;
typedef struct { KeyType key; }ElemType;
typedef struct { ElemType* R; int length; }SSTable;
int Search_Seq(SSTable ST, KeyType key) { for (int i = ST.length; i >= 1; i--) if (ST.R[i].key == key) return i; return 0; }
int Search_Seq(SSTable ST, KeyType key) { ST.R[0].key = key; int i = 0; for (i = ST.length; ST.R[i].key != key; i--); return i; }
int Search_Bin(SSTable ST, KeyType key) { int low = 1, high = ST.length; while (low <= high) { int mid = (low + high) / 2; if (ST.R[mid].key == key) return mid; else if (ST.R[mid].key > key) high = mid - 1; else low = mid + 1; } return 0; }
int Search_Bin(SSTable ST, KeyType key, int low, int high) { if (low > high) return 0; int mid = (low + high) / 2; if (ST.R[mid].key == key) return mid; else if (ST.R[mid].key > key) Search_Bin(ST, key, low, mid - 1); else Search_Bin(ST, key, mid + 1, high); }
int main() { return 0; }
|