just a basic algorithm... for homework. Yeah I don't know what to say about this homework. Kind of difficult for our classmates, but not for me. Oh and c++ version down there. ENJOY!
#include<iostream> using namespace std; bool BinarySearch(long long int array[], int target_number, int S_index, int E_index) { cout << "bs" << endl; if(array[S_index] == target_number){ cout << "arr[" << S_index << ']' << endl; return 1; } else if(array[E_index] == target_number){ cout << "arr[" << E_index << ']' << endl; } else if(E_index - S_index == 1){ return 0; } if(array[(S_index + E_index)/2] == target_number){ cout << "arr[" << (S_index + E_index)/2 << ']' << endl; return 1; } else if(array[(S_index + E_index)/2] < target_number){ return BinarySearch(array, target_number, (S_index + E_index)/2, E_index); } else{ return BinarySearch(array, target_number, S_index, (S_index + E_index)/2); } }