數據結構與算法----順序查找法

兩種方法 1.普通方法,倒序(順序)遍歷數組中的每一個元素,與查找元素相比較,時間複雜度爲O(n)。web static int search_seq2(int a[],int n,int key) { for(int i = n-1;i>=0;i--) { if(a[i] == key) return i; } return -1 ; } 2.哨兵方法。將數組第一個元素置爲要查找的元素,而後倒序
相關文章
相關標籤/搜索