Type*
binary_s(Type* array,
size_tsize, Type key) {
35int32_t lower_index(0), upper_index(size - 1), middle_index;
37 while(lower_index <= upper_index) {
38middle_index = std::floor((lower_index + upper_index) / 2);
40 if(*(array + middle_index) < key)
41lower_index = (middle_index + 1);
42 else if(*(array + middle_index) > key)
43upper_index = (middle_index - 1);
45 return(array + middle_index);
60uint32_t block_front(0), block_size = size == 0 ? 0 : 1;
61 while(block_front != block_size) {
62 if(*(array + block_size - 1) < key) {
63block_front = block_size;
64(block_size * 2 - 1 < size) ? (block_size *= 2) : block_size = size;
67 return binary_s<Type>(array + block_front, (block_size - block_front),
76 int* sorted_array =
new int[7]{7, 10, 15, 23, 70, 105, 203};
82 delete[] sorted_array;
Type * binary_s(Type *array, size_t size, Type key)
Type * struzik_search(Type *array, size_t size, Type key)
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4