Binary Search Write a C++ Program for searching an element on a given list of integers using the Binary Search method. Strictly adhere to the Object-Oriented specifications given in the problem statement. All class names, member variable names, and function names should be the same as specified in the problem statement. Initialize the array size in the constructor of the Search class. Function Description int search(int n, int k) The function defines the logic for searching an element from the given array. If the element is found return '1'. Otherwise, return '0'. Input Format: The first line is an integer 'n' which corresponds to the number of elements in the array. The next 'n' lines correspond to the elements of the array. The last line is an integer 'k' which corresponds to the key element to be searched. Output Format: Print "Element Found" if the element is present in the array otherwise print "Element not Found". [All text in bold corresponds to the input and the rest corresponds to output] Sample Input and Output 1: 5 1 2 3 4 5 3 Element found Sample Input and Output 2: 4 3 5 7 9 11 Element Not Found
Write a C++
Strictly adhere to the Object-Oriented specifications given in the problem statement. All class names, member variable names, and function names should be the same as specified in the problem statement.
Initialize the array size in the constructor of the Search class.
Function | Description |
int search(int n, int k) | The function defines the logic for searching an element from the given array. If the element is found return '1'. Otherwise, return '0'. |
Input Format:
The first line is an integer 'n' which corresponds to the number of elements in the array.
The next 'n' lines correspond to the elements of the array.
The last line is an integer 'k' which corresponds to the key element to be searched.
Output Format:
Print "Element Found" if the element is present in the array otherwise print "Element not Found".
[All text in bold corresponds to the input and the rest corresponds to output]
Sample Input and Output 1:
5
1
2
3
4
5
3
Element found
Sample Input and Output 2:
4
3
5
7
9
11
Element Not Found
Trending now
This is a popular solution!
Step by step
Solved in 2 steps with 1 images