Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
35 views3 pages

Empty 2. Size 3. Top 4. Push 5. Pop 6. Swap Mypqueue1.swap (Mypqueue2) 7. For Min Heap

This document provides summaries of common data structures and algorithms in C++ including: Priority queues allow storing elements in priority order and provide operations like push, pop, and top. Vectors store elements that can be accessed by index and support operations like push_back, erase, and insert. Pairs allow grouping two values together accessed by .first and .second. Unordered maps provide fast lookup of key-value pairs. Lower and upper bound functions find insertion points in a sorted range.

Uploaded by

joey lang
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
35 views3 pages

Empty 2. Size 3. Top 4. Push 5. Pop 6. Swap Mypqueue1.swap (Mypqueue2) 7. For Min Heap

This document provides summaries of common data structures and algorithms in C++ including: Priority queues allow storing elements in priority order and provide operations like push, pop, and top. Vectors store elements that can be accessed by index and support operations like push_back, erase, and insert. Pairs allow grouping two values together accessed by .first and .second. Unordered maps provide fast lookup of key-value pairs. Lower and upper bound functions find insertion points in a sorted range.

Uploaded by

joey lang
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Priority Queue

1. empty

2. size

3. top

4. push

5. pop

6. swap

mypqueue1.swap(mypqueue2);

7. For Min Heap

priority_queue <int, vector<int>, greater<int> > pq;

8. For Pairs(Ordered by First)

priority_queue<pair<int, int> > pq;

pq.push(make_pair(10, 200));

String

1. string str;
2. getline(cin,str);

3. int pos = str.find(".");


if (pos == string::npos)
return "";
4. reverse(str.begin(), str.end());
Queue

1.empty
2.size
3.swap
queue1.swap(queue2);
4.front
5.back
6.push
7.pop

Pair

1. pair <int, char> PAIR1 ;


PAIR1.first = 100;
PAIR1.second = 'G' ;

cout << PAIR1.first << " " ;


cout << PAIR1.second << endl ;

2. pair <string, double> PAIR3 ;


PAIR3 = make_pair ("GeeksForGeeks is Best",4.56);

Unordered_Map
1.unordered_map<string, int> umap;
2. if (umap.find(key) == umap.end())

cout << key << " not found\n\n";


Lower_bound and Upper_bound
sort(vect.begin(), vect.end());

// Returns the first occurrence of 20


auto q = lower_bound(vect.begin(), vect.end(), 20);

// Returns the last occurrence of 20


auto p = upper_bound(vect.begin(), vect.end(), 20);

cout << "The lower bound is at position: ";


cout << q-vect.begin() << endl;

cout << "The upper bound is at position: ";


cout << p-vect.begin() << endl;
Vector

1.push_back
2.erase(int position): Removes the element present at position. Ex:
v.erase(v.begin()+4); (erases the fifth element of the vector v)
3.erase(int start,int end): Removes the elements in the range from start to
end inclusive of the start and exclusive of the end
v.erase(v.begin()+2,v.begin()+5)

4. iterator1= vec1.begin();
vec1.insert ( iterator1+i , vec2[i] );
// This means that at position "i" from the beginning it will insert the value from vec2 from position i

You might also like