VOOZH about

URL: https://www.geeksforgeeks.org/cpp/stack-of-pair-in-c-stl-with-examples/

โ‡ฑ Stack of Pair in C++ STL with Examples - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Stack of Pair in C++ STL with Examples

Last Updated : 12 Jul, 2025
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. Syntax:
stack<pair<datatype, datatype>> stack_of_pair;
Below is an example to show the Stack of Pairs:
Output:
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)
Below are the images to show the working of Stack of Pairs: ๐Ÿ‘ Image
๐Ÿ‘ Image
Comment
Article Tags:
Article Tags: