顺序查找和二分查找的区别(顺序查找)
大家好!今天讓小編來大家介紹下關于順序查找和二分查找的區別(順序查找)的問題,以下是小編對此問題的歸納整理,讓我們一起來看看吧。
您好,今天芳芳來為大家解答以上的問題。順序查找和二分查找的區別,順序查找相信很多小伙伴還不知道,現在讓我們一起來看看吧!
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); }。
本文就為大家分享到這里,希望小伙伴們會喜歡。
以上就是小編對于順序查找和二分查找的區別(順序查找)問題和相關問題的解答了,順序查找和二分查找的區別(順序查找)的問題希望對你有用!
總結
以上是生活随笔為你收集整理的顺序查找和二分查找的区别(顺序查找)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 英国CMB色彩形象顾问(形象顾问)
- 下一篇: 奶性别游戏(奶性别)