#include<cstdio> #include<cstring> #include<cstdlib> int Sequential_Search1(int *a,int n,int key){ int i; for(i=0;i<=n;i++){ if(a[i] == key) return i; } return 0; } int Sequential_Search2(int *a,int n,int key){ int i; a[0] = key; i = n; while(a[i] != key){ i--; } return i; } int main(){ int a[11] = {0,3,123,42,67,36,51,8,45,1,55}; printf("普通顺序表查找:%d\n",Sequential_Search1(a,10,36)); printf("优化顺序表查找:%d\n",Sequential_Search2(a,10,36)); return 0; }
时间: 2024-10-06 00:56:23