prototypes for sorting.h
More...
Go to the source code of this file.
|
int | binary_search (int *poffset, int target, int *sorted_integers, int num_integers) |
|
template<typename doubletype > |
int | binary_search (int *poffset, doubletype target, doubletype *list, int length) |
|
prototypes for sorting.h
Definition in file sorting.h.
◆ binary_search() [1/2]
int binary_search |
( |
int * |
poffset, |
|
|
int |
target, |
|
|
int * |
sorted_integers, |
|
|
int |
num_integers |
|
) |
| |
Definition at line 14 of file binary_search.cpp.
29 end=sorted_integers+num_integers;
30 mid=beg+(int)(num_integers/2);
36 else if(*(end-1)==target){
38 offset=num_integers-1;
41 while((beg <= end) && (*mid != target)){
45 mid = beg + (end-beg)/2;
49 mid = beg + (end-beg)/2;
56 offset=mid-sorted_integers;
◆ binary_search() [2/2]
template<typename doubletype >
int binary_search |
( |
int * |
poffset, |
|
|
doubletype |
target, |
|
|
doubletype * |
list, |
|
|
int |
length |
|
) |
| |
Definition at line 9 of file sorting.h.
26 int n1 = int(length/2);
33 else if(target>=list[n2]){
40 if(list[n1]<=target && list[n1+1]>target){
45 else if(target < list[n1]){
47 n1 = n0 + int((n2-n0)/2);
51 n1 = n0 + int((n2-n0)/2);