#include using namespace std; void LinearSearch(int myArray[], int size, int key) { for (int c=0; c < size; c++) { // cout << "Count is " << c << endl; if (myArray[c] == key) { cout << "We found it at postion " << c << endl; } } } int BinarySearch(int myArray[], int size, int key) { int counter = 0; int start = 0; int end = size; int mid = size/2; cout << "First Middle is " << mid << endl; if (key <= myArray[mid]) { counter++; mid = mid/2; if (mid <= 0) { // not found cout << "Not found... " << endl; return 0; } cout << "Second Middle is " << mid << endl; cout << "Mid is really value = " << myArray[mid] << endl; if (key <= myArray[mid]) { counter++; if (myArray[mid] == key) { cout << "We found it at position " << mid << endl; cout << "It took " << counter << " tries." << endl; } else { mid = mid/2; if (mid <= 0) { // not found cout << "Not found... " << endl; return 0; } cout << "Third Middle is " << mid << endl; } } else if (key > myArray[mid]) { } } else if (key > myArray[mid]) { } } void JustANumber(int i) { cout << "Just a number " << i << endl; } int main() { int myNumbers[10] = {2, 3, 4, 5, 12, 16, 17, 18, 40, 90}; // LinearSearch(myNumbers, 10, 4); // JustANumber(myNumbers[2]); int status = BinarySearch(myNumbers, 10, 3); return 0; }