MCPcopy Create free account
hub / github.com/codemistic/Data-Structures-and-Algorithms / main

Function main

CPP/set & pair/seIterators.cpp:3–37  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1#include<bits/stdc++.h>
2using namespace std;
3int main(){
4
5//Set iterators offer less features than vectorr iterators.
6//auto it = s.begin(); //it is the iterator to the first element
7// it++, it--, ++it, --it ->These are all valid and wor in O(log N) time
8
9//NOTE: (it+5) or it+=2 etc are invalid. to advance multiple steps, do it++ multiple times.
10
11//elements of iteratir are always in sorted manner
12set<int> s;
13s.insert(4);
14s.insert(1);
15s.insert(10);
16s.insert(2);
17
18cout<<*s.begin()<<endl;
19
20s.erase(s.begin());
21cout<<*s.begin()<<endl;
22
23/* FUNCTIONS RELATED TO SET ITERATORS:
24 s.find(x): returns iterator to element with value x. Returns s.end() if not found. O(log N)
25
26 s.lower_bound(x): returns iterator to the first element which is >=x. Returns s.end() if not found. O(log N)
27
28 s.upperbound(x): returns iterator to the first element which is >x. Returns s.end() if not found. O(log N)
29
30 s.erase(it): erases the element with iterator it. O(log N)
31
32following 2 lines are same
33it(s.find(10)==s.end()) cout<<"Not found";
34it(s.count(10)==0) cout<<"Not found";
35*/
36 return 0;
37}

Callers

nothing calls this directly

Calls 1

insertMethod · 0.45

Tested by

no test coverage detected