Find implementation

xiaoxiao2021-03-06  71

#define maxSize 100typedef struct {datatype data [maxsize]; int lay;} slist;

Static lookup Table 1, sequentially look for int search_sequ (slist st, datatype x) {INT i; for (i = 0; i = st.Length) Return 0;}

2, two points to find a sequence table to find int search_bina (stable st, datatype x) {int low, high; low = 0; high = st.LENGTH-1; while (low <= high) {mid = (low high) ) / 2; if (k == st.data [mid]) Return MID; Else IF (k> st.data [mid]) loW = mid 1; else high = mid-1;} return 0;}

3. Find a slider lookup actually two lookups.

Dynamic look 1, binary sort tree

Typedef struct {keytype key;} elemType; typef struct bnot {elemType data; elemType * lchild, * rchild;} Bitree

INT Search_BST (Bitree * T, Keytype K, Bitree & P, Bitree & f) {f = NULL; P = T; While (P) {IF (k == p-> data.key) Return 1; ELSE IF (K < P-> Data.key) {f = p; p = p-> lchild;} else {f = p; p = p-> rchild;}} return 0;}

INT INSERT_BST (Bitree T, ELEMTYPE X) {BNODE * S; f = null; if (Search_BST (T, T, X.KeyType, P, F)) Return 0; Else {S = Malloc (SIZEOF (BNODE)); S- > data = x; s-> lchild = null: s-> rchild = null; if (! f) t = s; Else IF (x.key data.key) f-> lchild = s; Else F-> rchild = s; return 1;}}}

转载请注明原文地址:https://www.9cbs.com/read-87693.html

New Post(0)