-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathvector.cpp
More file actions
72 lines (58 loc) · 1.8 KB
/
vector.cpp
File metadata and controls
72 lines (58 loc) · 1.8 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
69
70
71
72
#include<bits/stdc++.h>
using namespace std;
//vector is used to store the elements in a linear fashion,when we dont want to store the elements in a distorted order
int main()
{
vector<int> arr;
// cout<<arr.size();
// cout<<arr.capacity()<<endl;
// arr.push_back(1);
// cout<<arr.size();
// cout<<arr.capacity()<<endl;
// arr.push_back(2);
// cout<<arr.size();
// cout<<arr.capacity()<<endl;
// arr.push_back(3);
// cout<<arr.size();
// cout<<arr.capacity()<<endl;
// vector<int> yash;
// yash.push_back(1);//instead of push_back() we can also use emplace_back(); as it is slightly faster than push back
// yash.push_back(5);
// yash.push_back(6);
// yash.push_back(4);
// yash.push_back(2);
// yash.push_back(3);
// for(auto it=yash.begin();it!=yash.end();it++)
// {
// cout <<*it<<" ";//it is not a variable its iterator hence we didnt used yash.at(it)
// }
// cout<<endl;
// vector<int> dev(yash);
// //or
// //vector<int> dev(yash.begin(),yash.end()); //works as [ ) first included and last not included
// for(auto it:dev)
// {
// cout <<it<<" ";
// }
// cout<<endl;
// swap(yash,arr); //used for swapping places
// for(auto it:yash)
// {
// cout<<it<<" ";
// }
// cout<<endl;
// //defining 2d vector
// vector<vector<int>> vec;
// vec.push_back(yash);
// vec.push_back(arr);
//defining a 10x20 vector
// vector<vector<int>> vctr(1,vector<int>(2,10));
// vctr.push_back(vector<int>(2,4));
// for(auto it:vctr){ //iterating 2d vector
// for(auto col:it){
// cout <<col<<endl;
// }
// }
// cout<<endl;
return 0;
}