📄 binarysearch.cpp
字号:
//************ BinarySearch.cpp *************
#include "BinarySearch.h"
Binarysearch::Binarysearch( int *xbptr,int xsearchKey,int xlow,int xhigh,int xsize )
:bptr(xbptr),searchKey(xsearchKey),low(xlow),high(xhigh),size(xsize)
{
bptr = new int [xsize];
for ( int i = 0; i < xsize; i++ )
bptr[i] = xbptr[i];
}
//int Binarysearch::search( int *xxbptr,int xxsearchKey,int xxlow,int xxhigh,int xxsize )
int Binarysearch::search()
{
int middle;
//bptr = xxbptr;
//for ( int i = 0; i < xxsize; i++ )
//b[i] = xxb[i];
//searchKey=xxsearchKey;
//low=xxlow;
//high=xxhigh;
//size=xxsize;
while ( low <= high )
{
middle = (low + high) / 2 ;
if ( searchKey == bptr[middle] )
return middle;
else
if( searchKey < bptr[middle] )
high = middle - 1;
else
low = middle + 1;
}
return -1;
}
Binarysearch::~Binarysearch()
{
delete[] bptr;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -