************************************************* 查 找 ************************************************* /*search an array, list, that has n numbers. Return i, if list[i] = searchnum. Return -1, if searchnum is not in the list*/
#define MAX_SIZE 1000 typedefstruct{ int key; /* other fields */ } element; element list[MAX_SIZE];
1.顺序查找 int seqsearch(intlist[],int searchnum,int n) { int i; for(i = 0; i < n; i++) if(list[i]== searchnum)break; return((i < n)? i :-1); }