-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathSTL_Sequence_container_Vector_1.cpp
152 lines (118 loc) · 4.94 KB
/
STL_Sequence_container_Vector_1.cpp
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
// author: jaydattpatel
/*
begin() – Returns an iterator pointing to the first element in the vector
end() – Returns an iterator pointing to the theoretical element that follows the last element in the vector
rbegin() – Returns a reverse iterator pointing to the last element in the vector (reverse beginning). It moves from last to first element
rend() – Returns a reverse iterator pointing to the theoretical element preceding the first element in the vector (considered as reverse end)
cbegin() – Returns a constant iterator pointing to the first element in the vector.
cend() – Returns a constant iterator pointing to the theoretical element that follows the last element in the vector.
crbegin() – Returns a constant reverse iterator pointing to the last element in the vector (reverse beginning). It moves from last to first element
crend() – Returns a constant reverse iterator pointing to the theoretical element preceding the first element in the vector (considered as reverse end)
*/
// iterators in vector
#include <iostream>
#include <string.h>
#include <vector>
using namespace std;
struct structure
{
public:
int aa;
char bb[20];
void show()
{
cout<<"\naa: "<<aa<<"\t\tbb : "<<bb;
}
};
class class_c
{
public:
int dd;
char ee[20];
void show()
{
cout<<"\ndd: "<<dd<<"\t\tee : "<<ee;
}
};
int main()
{
vector<int> int_list;
vector<char> char_list;
vector<structure> structure_list;
vector<class_c> class_list;
cout<<"\n\n---------------------------int_list---------------------------------------\n";
for (int i = 1; i <= 5; i++)
int_list.push_back(i);
cout << "\nint_list Output of begin and end: ";
for (auto i = int_list.begin(); i != int_list.end(); ++i)
cout << *i << " ";
cout << "\n\nint_list Output of cbegin and cend: ";
for (auto i = int_list.cbegin(); i != int_list.cend(); ++i)
cout << *i << " ";
cout << "\n\nint_list Output of rbegin and rend: ";
for (auto i = int_list.rbegin(); i != int_list.rend(); ++i)
cout << *i << " ";
cout << "\n\nint_list Output of crbegin and crend : ";
for (auto i = int_list.crbegin(); i != int_list.crend(); ++i)
cout << *i << " ";
cout<<"\n\n---------------------------char_list---------------------------------------\n";
for (int i = 65; i <= 70; i++)
char_list.push_back(i);
cout << "\nchar_list Output of begin and end: ";
for (auto i = char_list.begin(); i != char_list.end(); ++i)
cout << *i << " ";
cout << "\n\nchar_list Output of cbegin and cend: ";
for (auto i = char_list.cbegin(); i != char_list.cend(); ++i)
cout << *i << " ";
cout << "\n\nchar_list Output of rbegin and rend: ";
for (auto i = char_list.rbegin(); i != char_list.rend(); ++i)
cout << *i << " ";
cout << "\n\nchar_list Output of crbegin and crend : ";
for (auto i = char_list.crbegin(); i != char_list.crend(); ++i)
cout << *i << " ";
cout<<"\n\n---------------------------structure_list---------------------------------------\n";
for (int i = 1; i <= 5; i++)
{
static int num = 0;
num++;
structure *st = new structure;
(*st).aa = num;
sprintf((*st).bb,"struct-%d",(*st).aa);
structure_list.push_back(*st);
}
cout << "\nstructure_list Output of begin and end: ";
for (auto i = structure_list.begin(); i != structure_list.end(); ++i)
cout <<"\naa: "<<(*i).aa <<"\tbb: "<<(*i).bb<<"";
cout << "\n\nstructure_list Output of cbegin and cend: ";
for (auto i = structure_list.cbegin(); i != structure_list.cend(); ++i)
cout <<"\naa: "<<(*i).aa <<"\tbb: "<<(*i).bb<<"";
cout << "\n\nstructure_list Output of rbegin and rend: ";
for (auto i = structure_list.rbegin(); i != structure_list.rend(); ++i)
cout <<"\naa: "<<(*i).aa <<"\tbb: "<<(*i).bb<<"";
cout << "\n\nstructure_list Output of crbegin and crend : ";
for (auto i = structure_list.crbegin(); i != structure_list.crend(); ++i)
cout <<"\naa: "<<(*i).aa <<"\tbb: "<<(*i).bb<<"";
cout<<"\n\n---------------------------class_list---------------------------------------\n";
for (int i = 1; i <= 5; i++)
{
static int num = 0;
num++;
class_c *cc = new class_c;
cc->dd = num;
sprintf((*cc).ee,"class-%d",(*cc).dd);
class_list.push_back(*cc);
}
cout << "\nclass_list Output of begin and end: ";
for (auto i = class_list.begin(); i != class_list.end(); ++i)
cout <<"\naa: "<<(*i).dd <<"\tbb: "<<(*i).ee<<"";
cout << "\n\nclass_list Output of cbegin and cend: ";
for (auto i = class_list.cbegin(); i != class_list.cend(); ++i)
cout <<"\naa: "<<(*i).dd <<"\tbb: "<<(*i).ee<<"";
cout << "\n\nclass_list Output of rbegin and rend: ";
for (auto i = class_list.rbegin(); i != class_list.rend(); ++i)
cout <<"\naa: "<<(*i).dd <<"\tbb: "<<(*i).ee<<"";
cout << "\n\nclass_list Output of crbegin and crend : ";
for (auto i = class_list.crbegin(); i != class_list.crend(); ++i)
cout <<"\naa: "<<(*i).dd <<"\tbb: "<<(*i).ee<<"";
return 0;
}