-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path23.cpp
More file actions
38 lines (28 loc) · 1.09 KB
/
Copy path23.cpp
File metadata and controls
38 lines (28 loc) · 1.09 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
#include <bits/stdc++.h>
using namespace std;
int main() {
// vector<int> v = {2, 3, 5, 6, 7};
// // vector<int>::iterator it = v.begin();
// // cout<<*(it+1)<<"\n"; // +1 in iterator only works when it is continous memory allocation
// for (auto it = v.begin(); it != v.end(); it++)
// {
// cout<<*it<<"\n";
// }
// // ***************************
// // map and set are not continous
// // thus it+1 will not work
// // but it++ will work because it will take it to next element but in case of it+1 it moving to next address
// // ****************************
vector<pair<int,int>> v_p = {{1, 2}, {2, 3}, {3, 4}};
vector<pair<int,int>>:: iterator it; // declare iterator with the same datatype jo uske container ka hai
for ( it = v_p.begin(); it != v_p.end(); it++)
{
cout<<(*it).first<<" "<<(*it).second<<"\n";
}
for ( it = v_p.begin(); it != v_p.end(); it++)
{
cout<<it->first<<" "<<it->second<<"\n";
// we can also use this syntax when iterator is pointing to a pair
}
return 0;
}