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

Function main

CPP/set & pair/basicSetFunctions.cpp:3–30  ·  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 is a container which keeps a unique copy of every element in sorted order.
6
7set<int>s; //empty set of integers
8//set<string>s; //empty set of strings
9
10s.insert(20);
11s.insert(30);
12cout<<s.count(10)<<endl;
13cout<<s.count(20)<<endl;
14cout<<s.count(40)<<endl;
15cout<<s.count(30)<<endl;
16cout<<s.count(110)<<endl;
17
18s.erase(10);
19cout<<s.count(10)<<endl;
20/* IMPORTANT FUNCTIONS
21s.insert(x); - insert the value x into set, do nothing if already present. O(log N)
22s.erase(x); - erase the value x from set if present. O(log N)
23s.count(x); -returns 0 if x ain't in the set and 1 if it's there. O(log N)
24s.clear()- erase all elements. O(N)
25s.size()- returns the current size of the set. O(1)
26
27WRONG: cout<<s[0]; //operator doesnt work with sets
28*/
29
30}

Callers

nothing calls this directly

Calls 1

insertMethod · 0.45

Tested by

no test coverage detected