⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 search.h

📁 这是本人精心搜集的关于常用图论算法的一套源码
💻 H
字号:
#include "Ordered_list.h"
Error_code sequential_search(Ordered_list& the_list, const int &target, int &position)
{ for( position=0; position<the_list.size( ); position++)
     { Record x;
       the_list.retrieve(position, x);
       if(x==target) return success;
     }
  return not_present;            // 脱离for,则检索不成功
} 
Error_code binary_search(Ordered_list& the_list, const int &target, int &position)
{ int bottom=0, top=the_list.size()-1;                // 置区间初值   
   while(bottom<=top)
    { int mid=(bottom+top)/2;  
      Record x;   the_list.retrieve(mid,x);
      if(target==x)               // 检索成功
        {  position = mid;  return success; }
      if(target>x) bottom=mid+1; // 修改下界 bottom 值
         else top=mid-1;         // 修改上界top值
    }
   return not_present;           // 脱离while,则 bottom>top 检索不成功
} 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -