-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path0002vector.cpp
More file actions
91 lines (73 loc) · 2.41 KB
/
0002vector.cpp
File metadata and controls
91 lines (73 loc) · 2.41 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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#include<iostream>
#include<vector>
using namespace std;
// vector will double its size when you reached the end element of the vector size
int main(){
// initialisation
vector<int> v;
cout<<"Size Of vector --> "<<v.size()<<endl<<endl;
cout<<"capacity of vector --> "<<v.capacity()<<endl;
v.push_back(2);
cout<<"capacity of vector --> "<<v.capacity()<<endl;
v.push_back(3);
cout<<"capacity of vector --> "<<v.capacity()<<endl;
v.push_back(4);
cout<<"capacity of vector --> "<<v.capacity()<<endl;
v.push_back(7);
cout<<"capacity of vector --> "<<v.capacity()<<endl;
cout<<"Size Of vector --> "<<v.size()<<endl;
// getting the element by Index of The vector
cout<<"Element At Second Index "<< v.at(2)<<endl;
// gettig the front and back elements of the vector
cout <<"The Front Element : "<<v.front()<<endl;
cout <<"The Back Element : "<<v.back()<<endl;
//befor pop the vector
cout<<"Befor The POP Vector "<<endl;
for(auto i : v){
cout << i << " ";
}cout<<endl;
v.pop_back();// poping the element form back of the vector index
cout<<"After The POP Vector "<<endl;
for(auto i : v){
cout << i << " ";
}cout<<endl;
cout<<"Befor the clear size of vector : "<<v.size()<<endl;
v.clear();
cout<<"After The Clear Size Of Vector : "<<v.size()<<endl;
// initialising the vector with size deffined
vector<int> a(5,1); // here the 5 is the size of the entire vector & 1 are the default element of the vector
// a =[1,1,1,1,1]
for(auto i: a ){
cout<< i<<" ";
}cout<<endl;
vector<int> last(a);// copieing the old vector and creating the new on with the help of that old one
// here the a is an referance vector for last named vector
for(auto i : last ){
cout<< i << " ";
}cout<<endl;
last.push_back(3);
for(auto i : last ){
cout<< i << " ";
}cout<<endl;
}
/*
Size Of vector --> 0
capacity of vector --> 0
capacity of vector --> 1
capacity of vector --> 2
capacity of vector --> 4
capacity of vector --> 4
Size Of vector --> 4
Element At Second Index 4
The Front Element : 2
The Back Element : 7
Befor The POP Vector
2 3 4 7
After The POP Vector
2 3 4
Befor the clear size of vector : 3
After The Clear Size Of Vector : 0
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1 3
*/