正在加载图片...
顺序查找的算法: 使用了监视哨, int Search seq( ssTable ST,intn, int key))在查找过程中, i int i=n; 不用每一步都去 判断是否查找结 stio. key=key; 束。 while(sti. key!=key)i-;/从表尾往前查找到:返回元素 return i 01234在线性表中的存 10|204080储位置; (a)初乱未找到:返回0 314567 8010204080306025 ○ 监视哨 (b)K-80 (return i=4) 0123456 9010204080306025 (c)K=90 (return i=0)0 1 2 3 4 5 6 7 (a) 初态 10 20 40 80 30 60 25 (b) K=80 (return i=4) 80 10 20 40 80 30 60 25 0 1 2 3 4 5 6 7 (c) K=90 (return i=0 ) 0 1 2 3 4 5 6 7 90 10 20 40 80 30 60 25 顺序查找的算法: int Search_seq(SSTable ST[ ], int n, int key) { int i=n; ST[0].key=key; while(ST[i].key!=key) i- -; /*从表尾往前查*/ return i; } 监视哨 使用了监视哨, 在查找过程中, 不用每一步都去 判断是否查找结 束。 找到:返回元素 在线性表中的存 储位置; 未找到:返回0
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有