《顺序查找.pptVIP

  • 6
  • 0
  • 约1.89千字
  • 约 7页
  • 2016-12-29 发布于北京
  • 举报
* 西南财经大学天府学院 LOGO 顺序查找(Sequential Search) Evaluation only. Created with Aspose.Slides for .NET 3.5 Client Profile 5.2.0.0. Copyright 2004-2011 Aspose Pty Ltd. 顺序查找(Sequential Search) 基本思想:从顺序表的一端向另一端逐个将表中的数据与给定的目标值进行比较,若相等,则查找成功,并给出该目标值在表中的位置;若整个表检测完仍未找到与目标值相等的数据,则查找失败,给出查找失败信息。 Evaluation only. Created with Aspose.Slides for .NET 3.5 Client Profile 5.2.0.0. Copyright 2004-2011 Aspose Pty Ltd. a i=9 a i=0 60 i=11 Target = 80 Target = 60 i=11 80 顺序查找——哨兵查找( Sentinel search ) 基本思想:设置“监视哨”。哨兵就是待查值,将它放在查找方向的尽头处。 i=10 Evaluation only. Created with Aspose.Slides for .NET 3.5 Client Profile 5.2.0.0. Copyright 2004-2011 Aspose Pty Ltd. 哨兵查找算法 (Sequential Search algorithm ) 算法需要完成两件事: 是否找到目标数据:Target 如果找到,在顺序表中的位置在哪里,即返回the index。 Evaluation only. Created with Aspose.Slides for .NET 3.5 Client Profile 5.2.0.0. Copyright 2004-2011 Aspose Pty Ltd. algorithm seqsearch(val list array val last index val target keytype ref locn index) list [0] = target // 设置“监视哨” looker=last loop (target not equal list [looker]) looker = looker - 1 end loop locn = looker if (looker 0) found = true locn = looker else found = false locn = 0 end if return found end sentinel search 哨兵查找算法(Sequential Search algorithm ) Evaluation only. Created with Aspose.Slides for .NET 3.5 Client Profile 5.2.0.0. Copyright 2004-2011 Aspose Pty Ltd. 哨兵查找算法(C语言实现) #include ”stdio.h” main() { } int a[12]={-1,21,37,88,19,92,5,64,56,80,75,13}; int target,i; a[0]=target; printf(“Enter your search target(an integer):”); scanf(“%d”,target); printf(“The target has been found,it’s intex is:%d\n”,i); else printf(“The target isn’t found.\n”); i=11; while(a[i]!=target) { } i=i-1; if(i0) Evaluation only. Created with Aspose.Slides for .NET 3.5 Client Profile 5.2.0.0. Copyright 2004-2011 Aspose Pty Ltd.

文档评论(0)

1亿VIP精品文档

相关文档