Changeset 13572
- Timestamp:
- 10/09/12 20:33:14 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
issm/trunk-jpl/src/c/shared/Sorting/binary_search.cpp
r13569 r13572 18 18 19 19 /*intermediary: */ 20 int * beg=NULL;21 int * end=NULL;22 int * mid=NULL;20 int *beg = NULL; 21 int *end = NULL; 22 int *mid = NULL; 23 23 24 24 // point to beginning and end of the array … … 69 69 int offset=0; 70 70 int found=0; /*found=0: not found. 71 72 73 71 found=1: found, and target is == to value at offset 72 found=2: found, and target is > to value at offset and < to value at offset+1 73 */ 74 74 75 75 /*intermediary: */ 76 double * beg=NULL;77 double * end=NULL;78 double * mid=NULL;76 double *beg = NULL; 77 double *end = NULL; 78 double *mid = NULL; 79 79 80 80 // point to beginning and end of the array 81 beg =sorted_doubles;82 end =sorted_doubles+num_doubles;83 mid =beg+(int)(num_doubles/2.0);81 beg = sorted_doubles; 82 end = sorted_doubles+num_doubles; 83 mid = beg+(int)(num_doubles/2.0); 84 84 85 85 if (target<*beg){ 86 offset ==-1;87 found =0;86 offset = -1; 87 found = 0; 88 88 } 89 89 if (*beg==target){ 90 found =1;91 offset =0;90 found = 1; 91 offset = 0; 92 92 } 93 93 else if(*(end-1)==target){ 94 found =1;95 offset =num_doubles-1;94 found = 1; 95 offset = num_doubles-1; 96 96 } 97 97 else{ 98 while((beg <= end) && !( target>=*mid && 98 while((beg <= end) && !( target>=*mid && target<*(mid+1)) ){ 99 99 // is the target in lower or upper half? 100 100 if (target < *mid) {
Note:
See TracChangeset
for help on using the changeset viewer.