-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathalgorithm.cpp
More file actions
68 lines (57 loc) · 1.31 KB
/
algorithm.cpp
File metadata and controls
68 lines (57 loc) · 1.31 KB
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#include<iostream>
#include<algorithm>
//binary search, sort, swap, min/max, reverse/rotate, upper/lower bound.
#include<vector>
using namespace std;
int main()
{
int a;
vector<int> v,z;
v.push_back(1);
v.push_back(2);
v.push_back(5);
v.push_back(4);
v.push_back(3);
v.push_back(6);
v.push_back(7);
v.push_back(8);
v.push_back(9);
v.push_back(10);
// cout<<binary_search(v.begin(),v.end(),5)<<"\n";
// cout<<max(v.at(1),v.at(2))<<"\n"; //max .at uses index
// cout<<min(v.at(4),v.at(2))<<"\n"; //min
// cout<<"Before swap: ";
// for(int i:v)
// {
// cout<<i<<" ";
// }
// swap(v.at(4),v.at(2)); //swap
// cout<<"\nAfter swap: ";
// for(int i:v)
// {
// cout<<i<<" ";
// }
// cout<<"\nReversing vector: ";
// reverse(v.begin(),v.end());
// for(int i:v)
// {
// cout<<i<<" ";
// }
// sort(v.begin(),v.end());
// rotate(v.begin(),v.begin()+3/*no. of element rotated*/,v.end());
// cout<<"\nAfter rotation: ";
// for(int i:v)
// {
// cout<<i<<" ";
// }
v.swap(z); //swap will not work why??
for(int i:v)
{
cout<<i<<" ";
}
cout<<endl;
for(int i:z)
{
cout<<i<<" ";
}
}