顺序查找 && 折半查找
顺序查找 算法描述 顺序比较即可。 平均查找长度 (n+1)/2, 其中n为表长。 时间复杂度 O(n) #include "stdio.h" typedef struct student{ int id; /*学生编号*/ char name[10]; /*学生姓名*/ float score; /*成绩*/ }Student; int search(Student stu[],int n,int key){ int i; for(i=0; i<n; i++) if( stu[i].id == key ) /*查找成功*/ return i; return -1; /*查找失败*/ } void main() { Student stu[4] = {{1004,"TOM",100} , {1002,"LILY",95}, {1001,"ANN",93}, {1003,"LUCY",98} }; /*初始化结构体数组*/ int addr; /*要查找的记录的地址*/ addr = search(stu,4,1003); printf("Student ID: %d\n",stu...
