Stack Data Structure in C++
Hey there, in this writing I’m going to discuss the array implementation of stack and queue. Note that it is not ideal because using an array in the place of a linked list has some drawbacks we’ll discuss later.
First of all, we have to remember that, we can’t change array size once we’ve declared it. That means the stack and queue’s max size limit will depend on the array size.
Previously we’ve learned about the linked list implementations of the stack and queue. You can check it out if you are not already learned about it.
What is a stack?
Stack is a linear data structure that follows a particular order in which the operations are performed. The order may be LIFO(Last In First Out)
Imagine a case where you have a pile of books and the books are placed one upon another. Now you have to pick the bottommost book from the pile. To do so, you have to pick the topmost book first, then the second book, and so on until the last book. Here, we can say the book at the top was placed at the end. In the scenario, the pile is called a stack.
Top comments (0)