forked from thesaadpatel/Cpp-codes
-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathvector.cpp
More file actions
54 lines (29 loc) · 692 Bytes
/
vector.cpp
File metadata and controls
54 lines (29 loc) · 692 Bytes
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
#include<iostream>
#include<vector>
using namespace std;
int main()
{
vector<int> v1;
vector<int> :: iterator it;
v1.push_back(5);
while(v1.back()!=0){
v1.push_back(v1.back()-1);
}
// end(): Returns an iterator pointing to a position which is NEXT to the last element of the vector.
// So sweet of you c++;
// Address
for(it=v1.begin();it!=v1.end();it++){
cout<<*it<<' ';
}
cout<<endl ;
for(int i=0;i<v1.size();i++){
cout<<v1.at(i)<<' ';
}
cout<<endl ;
while(!v1.empty()){
cout<<v1.back()<< ' ';
v1.pop_back();
}
cout<<endl ;
return 0;
}