list <Type> name_of_list;
Stack are a type of container adaptor with LIFO(Last In First Out) type of work, where a new element is added at one end and (top) an element is removed from that end only.
stack <Type> name_of_stack;
List of Stacks are a type of container which have a series of stacks, this is a two-dimensional container where N rows of list and M column of stacks, size of both dimension is non-fixed. which can be traversed and accessed using iterators.
list <stack <Type> > name_of_container(size);
where size is optional
list <stack <int> > ls(10);
size of list of stacks is 10
Insertion: Insertion in the list of the stack is done using the push() function.
Above code traverses list<int> ls at each index using starting iterators ls.begin() and ending iterator ls.end(). For accessing the element it uses (*it) as stack are pointers pointing to elements in list <stack <int> > ls.
Below is the program to illustrate the insertion and traversal in lists of stacks:
List of stack is : 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 9 8 7 6 5 4 3 2 9 8 7 6 5 4 3 9 8 7 6 5 4 9 8 7 6 5 9 8 7 6 9 8 7 9 8 9
Rated as one of the most sought after skills in the industry, own the basics of coding with our C++ STL Course and master the very concepts by intense problem-solving.
- Implement two stacks in an array
- Iterative Postorder Traversal | Set 1 (Using Two Stacks)
- Bubble sort using two Stacks
- Sorting array using Stacks
- Merging and Sorting Two Unsorted Stacks
- Infix to Prefix conversion using two stacks
- Sudo Placement[1.3] | Playing with Stacks
- Add two numbers represented by Stacks
- Check if the two given stacks are same
- Maximize sum of topmost elements of S stacks by popping at most N elements
- Find maximum sum possible equal sum of three stacks
- Queue using Stacks
- How to efficiently implement k stacks in a single array?
- list::push_front() and list::push_back() in C++ STL
- list::pop_front() and list::pop_back() in C++ STL
- list::front() and list::back() in C++ STL
- list::empty() and list::size() in C++ STL
- list::remove() and list::remove_if() in C++ STL
- list::emplace_front() and list::emplace_back() in C++ STL
- list::begin() and list::end() in C++ STL
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. 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.