-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvector.txt
More file actions
37 lines (23 loc) · 1.13 KB
/
vector.txt
File metadata and controls
37 lines (23 loc) · 1.13 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
Using dynamic array in C++ // vectors
push_back ( ) // can be used for taking input.
int main(){
vector <int> g1; // declaring the array;
vector <int> :: iterator i; // declaring the iterator
vector <int> :: reverse_iterator ir; // declaring the reverse iterator
1. begin() – Returns an iterator pointing to the first element in the vector
2. end() – Returns an iterator pointing to the theoretical element that follows last element in the vector
3. rbegin() – Returns a reverse iterator pointing to the last element in the vector (reverse beginning). It moves from last to first element
4. rend() – Returns a reverse iterator pointing to the theoretical element preceding the first element in the vector (considered as reverse end)
for (int i = 1; i <= 5; i++)
g1.push_back(i); // pushing the input inside the array
cout << "Output of begin and end\t:\t";
for (i = g1.begin(); i != g1.end(); ++i)
cout << *i << '\t';
OUTPUT- 1 2 3 4 5
cout << "Output of rbegin and rend\t:\t";
for (ir = g1.rbegin(); ir != g1.rend(); ++ir)
cout << '\t' << *ir;
output 5 4 3 2 1
return 0;
}
--