实现有序表二分查找

二分查找递归与非递归

//算法7.3 折半查找



#include
using namespace std;
#define MAXSIZE 100
#define OK 1;

typedef struct{
    int key;//关键字域
}ElemType;

typedef struct{
    ElemType *R;
    int length;
}SSTable;

int InitList_SSTable(SSTable &L)
{
    L.R=new ElemType[MAXSIZE];
    if (!L.R)
    {
        cout<<"初始化错误";
        return 0;
    }
    L.length=0;
    return OK;
}

int Insert_SSTable(SSTable &L) 
{
    int j=1;
    for(int i=1;ihigh){
     return 0;
   }
   //while(low<=high) {
      mid=(low+high) / 2;
      if (key==ST.R[mid].key)  return mid;              //找到待查元素
      else if (key>testkey1>>testkey2;

    cout<<"非递归折半查找"<

你可能感兴趣的:(实现有序表二分查找)