-
Notifications
You must be signed in to change notification settings - Fork 0
/
Algorithms and its Operations
44 lines (38 loc) · 1.04 KB
/
Algorithms and its Operations
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
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
int main() // for binary search
{
vector<int> v;
v.push_back(1);
v.push_back(3);
v.push_back(6);
v.push_back(7);
cout<<"finding 6 -> "<<binary_search(v.begin(),v.end(),6)<<endl;
cout<<"finding 5 -> "<<binary_search(v.begin(),v.end(),5)<<endl;
cout<<"lower bound -> "<<lower_bound(v.begin(),v.end(),6)-v.begin()<<endl;
cout<<"upper bound -> "<<upper_bound(v.begin(),v.end(),6)-v.begin()<<endl;
int a=3, b=5; // to find min and max
cout<<"max -> "<<max(a,b)<<endl;
cout<<"min -> "<<min(a,b)<<endl;
swap(a,b);
cout<<"a -> "<<a<<endl;
cout<<"b -> "<<b<<endl;
string s="abcde";
reverse(s.begin(), s.end());
cout<<"string -> "<<s<<endl;
rotate(v.begin(), v.begin()+1, v.end());
cout<<"after rotate"<<endl;
for(int i:v)
{
cout<<i<<" ";
}
sort(v.begin(), v.end());
cout<<"after sortin"<<endl;
for(int i:v)
{
cout<<i<<" ";
}
return 0;
}