【资料图】
1、#include
2、int Search_Seq(SSTable ST, KeyType key){ int i; for(i=1; i<=ST.length && ST.elem[i] != key; i++ ) ; if(i<=ST.length) return i; else return 0;}*/int Search_Seq(SSTable ST, KeyType key){ int i; ST.elem[0] = key; //“哨兵”,如果顺序表中不存在要查找的数据的话,则查找指针必定指向该哨兵 for(i = ST.length; ST.elem[i] != key; i--) ; return i; //找到的话,则i != 0,否则i = 0}void main(){ int i, key; SSTable T; T.elem = (KeyType *)malloc(sizeof(KeyType)); printf("How Many Entries Do You Want input"); scanf("%d", &T.length); for(i=1; i<=T.length; i++){ printf("Please input the %dth entries ", i); scanf("%d", &T.elem[i]); } for (i=1; i<=T.length; i++) printf("%5d",T.elem[i]); //显示已经输入的所有数据 printf("Please input the data you want to search"); scanf("%d", &key); i = Search_Seq(T,key); printf("the search data is locate the %dth(0 indicate can not find)",i); }。
本文就为大家分享到这里,希望小伙伴们会喜欢。
标签: