實現順序查詢的演算法

2021-08-13 03:28:53 字數 703 閱讀 2656

#include 

#define maxl 100 //定義表中最多記錄個數

typedef

int keytype;

typedef

char infotype[10];

typedef

struct

nodetype;

typedef nodetype seqlist[maxl]; //順序表型別

int seqsearch(seqlist r,int n,keytype k) //順序查詢演算法

if (i>=n)

return -1;

else

}int main()

; for (i=0;i//建立順序表

r[i].key=a[i];

printf("關鍵字序列:");

for (i=0;iprintf("%d ",r[i].key);

printf("\n");

printf("查詢%d所比較的關鍵字:\n\t",k);

if ((i=seqsearch(r,n,k))!=-1)

printf("\n元素%d的位置是%d\n",k,i);

else

printf("\n元素%d不在表中\n",k);

printf("\n");

}

實現順序查詢的演算法

編寫乙個程式exp9 1.cpp,輸出在順序表 3,6,2,10,1,8,5,7,4,9 中採用順序查詢方法查詢關鍵字5的過程。檔名 exp9 1.cpp include define maxl 100 定義表中最多記錄個數 typedef int keytype typedef char info...

查詢演算法 順序查詢

又叫線性查詢 我們來看乙個題目 科大有學生成績分布如下 1,8,10,89,1000,1234 要求 判斷數列是否包含某個特定的值 這裡我就不舉例 直接在題目中展示 找到了就返回值以及下標 順序查詢演算法 author 王 public class seqsearch 無序的陣列 int index...

查詢演算法 順序查詢

python 和 golang 實現 linear search 順序查詢 從列表的第乙個元素開始,按照順序對列表進行搜尋,找到待查詢的元素就返回其下標,找不到就返回none或 1 pythondef linear search data list,value for i in range 0,le...