-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbinaryStl.cpp
46 lines (27 loc) · 828 Bytes
/
binaryStl.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
#ifndef ONLINE_JUDGE
// for getting input from input.txt
freopen("input.txt", "r", stdin);
// for writing output to output.txt
freopen("output.txt", "w", stdout);
#endif
int arr[] = {10,43,43,43,43,54,75,86};
int n = sizeof(arr)/sizeof(int);
int key;
cin>>key;
bool present = binary_search(arr,arr+n, key);
if(present) {
cout<<"present"<<endl;
} else {
cout<<"not present";
}
int* it = lower_bound(arr,arr+n,key);
cout<<"lowr bound" << (it-arr) <<endl;
// upper bound - lower bpiond gives the frequency of the elements availabe in the sorted array
int* uit = upper_bound(arr,arr+n,key);
cout<<"uppr bound"<<(uit-arr)<<endl;
return 0;
}