testbinarysearch.cpp

来自「C++编成数据结构与程序设计方法 D.S.Malk编著」· C++ 代码 · 共 24 行

CPP
24
字号
#include <iostream>
#include "searchSortAlgorithms.h"
 
using namespace std;

int main()
{
    int intList[] = {2, 16, 34, 45, 53, 
                     56, 69, 70, 75, 96};           //Line 1

    int pos;                                        //Line 2

    pos = binarySearch(intList, 10, 45);            //Line 3

    if (pos != -1)                                  //Line 4
        cout << "Line 5: " << 45
             << " found at position " 
             << pos << endl;                        //Line 5
    else                                            //Line 6
        cout << "Line 7: " << 45 
             << " is not in intList " << endl;      //Line 7
    return 0;
}

⌨️ 快捷键说明

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