Stack in STL Stacks are a type of container adaptors with LIFO(Last In First Out) type of working, where a new element is added at one end and (top) an element is removed from that end only.
Pair in STL The pair container is a simple container defined in header consisting of two data elements or objects. The first element is referenced as ‘first’ and the second element as ‘second’ and the order is fixed (first, second).
Stack of pair in STL: Stack of pair can be very efficient in designing complex data structures.
stack<pair<datatype, datatype>> stack_of_pair;
Below is an example to show the Stack of Pairs:
Stack of Pairs: (7, 9) (5, 10) (1, 5) (15, 5) (10, 20) Size of Stack of Pairs: 5 Top of Stack of Pairs: (7, 9) Removing the top pair Current Stack of Pairs: (5, 10) (1, 5) (15, 5) (10, 20)
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- stack empty() and stack size() in C++ STL
- Stack | Set 3 (Reverse a string using stack)
- Sort a stack using a temporary stack
- Stack Permutations (Check if an array is stack permutation of other)
- Infix to Postfix using different Precedence Values for In-Stack and Out-Stack
- Find maximum in stack in O(1) without using additional stack
- Stack in C++ STL
- stack swap() in C++ STL
- stack top() in C++ STL
- stack push() and pop() in C++ STL
- stack emplace() in C++ STL
- std::tuple, std::pair | Returning multiple values from a function using Tuple and Pair in C++
- Queries to check if any pair exists in an array having values at most equal to the given pair
- Sorting an array according to another array using pair in STL
- Difference between pair in Multiset and Multimap in C++ STL
- Pair in C++ Standard Template Library (STL)
- multiset lower_bound() in C++ STL with Examples
- multiset max_size() in C++ STL with Examples
- forward_list max_size() in C++ STL with Examples
- array data() in C++ STL with Examples
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.