DEV Community

hafizpustice05
hafizpustice05

Posted on

Stack Implementation Using Linked List in c++

Stack Implementation Using Linked List in c++
The stack and queue data structures are among the most widely used data structures. When we have no predefined size of the array, besides we need to perform push/ enqueue and pop/ dequeue operation in O(1) time complexity, most probably we need to use stack or queues there.

In this writing, I’m going to discuss the stack and queue and its implementation using a linked list. If you have no previous idea about what a linked list is, you are recommended to read this article before starting this.

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.

Stack Implementation Using Linked List in c++

Top comments (0)