![]() |
In C++, a stack of vectors can be created using the Standard Template Library (STL). The stack is a container adapter that provides a Last-In-First-Out (LIFO) type of data structure, and a vector is a dynamic array that can grow and shrink in size. In this article, we will learn how to create a stack of vectors in C++. Example Input: myVector1 = { 1, 4, 3, 2, 10} myVector2 = {5, 1, 3, 4, 8} Output: myStack: [ { 1, 4, 3, 2, 10}, Stack of Vectors in C++To create a std::stack of std::vector, we can define the type of stack as the std::vector by passing it as the template parameter. In this way, each element of the stack will be a vector. Syntax to Declare a Stack of Vectorstack <vector <type>> myStack;
C++ Program to Create a Stack of VectorsC++
Output
MyStack: {7 8 9 } {4 5 6 } {1 2 3 } Time Complexity: O(N), where N is the number of vectors. |
Reffered: https://www.geeksforgeeks.org
C++ |
Type: | Geek |
Category: | Coding |
Sub Category: | Tutorial |
Uploaded by: | Admin |
Views: | 13 |