Last active
October 21, 2017 14:49
-
-
Save TheRoyalDebugger/ce45e1744e65916bd72fa02c4bc3f3c2 to your computer and use it in GitHub Desktop.
Revisions
-
TheRoyalDebugger revised this gist
Oct 21, 2017 . 1 changed file with 1 addition and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -24,6 +24,7 @@ using namespace std; int main(){ int element; //Array must be sorted int arrData[] = {10,20,30,144,232,353}; cout<<"Enter element to search:"<<endl; cin>>element; -
TheRoyalDebugger created this gist
Oct 21, 2017 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,37 @@ #include<iostream> using namespace std; bool isBinarySearchFoundElement(int* arrData,int searchElement,int left, int right){ if(left > right){ return false; } int mid = left + (right-left)/2; if(arrData[mid] == searchElement){ return true; }else if(searchElement < arrData[mid]){ isBinarySearchFoundElement(arrData,searchElement,left,mid-1); }else{ isBinarySearchFoundElement(arrData,searchElement,mid+1,right); } return false; } bool isFoundData(int* arrData,int element){ int right = sizeof(arrData)/sizeof(arrData[0]); bool isDataFound = isBinarySearchFoundElement(arrData,element,0,right); return isDataFound; } int main(){ int element; int arrData[] = {10,20,30,144,232,353}; cout<<"Enter element to search:"<<endl; cin>>element; bool isFound = isFoundData(arrData,element); if(isFound == true){ cout<<"Element found in array!"<<endl; }else{ cout<<"Element does not exist in array!"; } return 0; }