//-----------------Binary Search Algorithm(use by struziki algorithm//-----------------
//Time Complexity O(log n) where 'n' is the number of elements
//Worst Time Complexity O(log n)
//Best Time Complexity Ω(1)
//Space Complexity O(1)
//Auxiliary Space Complexity O(1)
template<classType>inlineType*binary_search(Type*array,size_tsize,Typekey){//Parameter List:Pointer to and array|size of array|key what you search
int32_tlower_index(0),upper_index(size-1),middle_index;//lower_index => start of search range | upper_index => end of search range | middle_index => middle of search range
//-----------------Binary Search Algorithm(use by Struzik algorithm)-----------------
// Time Complexity O(log n) where 'n' is the number of elements
// Worst Time Complexity O(log n)
// Best Time Complexity O(1)
// Space Complexity O(1)
// Auxiliary Space Complexity O(1)
template<classType>inlineType*binary_search(Type*array,size_tsize,Typekey){//Parameter List:Pointer to an array|size of array|key what you search
int32_tlower_index(0),upper_index(size-1),middle_index;//lower_index => start of search range|upper_index => end of search range
while(lower_index<=upper_index)
{
middle_index=floor((lower_index+upper_index)/2);
if(*(array+middle_index)<key)lower_index=(middle_index+1);//if the key is smaller than the middle of search range, we narrow the search range from up
elseif(*(array+middle_index)>key)upper_index=(middle_index-1);//if the key is bigger than the middle of search range, we narrow the search range from down
elsereturn(array+middle_index);//the key has been found
if(*(array+middle_index)<key)lower_index=(middle_index+1);//narrow the search range from up
elseif(*(array+middle_index)>key)upper_index=(middle_index-1);//narrow the search range from down
elsereturn(array+middle_index);//key has been found
//Time Complexity O(log i)where i is the position of the search key in the list
//Worst Time Complexity O(log i)
//Best Time Complexity Ω(1)
//Space Complexity O(1)
//Auxiliary Space Complexity O(1)
template<classType>Type*Struzik_Search(Type*array,size_tsize,Typekey){//Parameter List: Pointer to an array(sorted)!You can use complex objectum, but in that case you have to overload '<>' operators!|size of array|key what you search
uint32_tblock_front(0),block_size=size==0?0:1;//the start and end of the first block where the algorithm starts seach !if the size of array 0 than return null pointer
while(block_front!=block_size)//when the start of block(block_front) and end of block(block_size) equal it means the key bigger than the last element of array and it return null pointer