Stack & Queue 101

                           On the previous post, we have already discussed about the concept of Linked List and some of the example of Linked List itself. Now we are going to continue with our next discussion topic regarding the concept of Stack and Queue. These two concepts has the same concept of storing it's elements of data in an ordered manner however, the way on how operate are completely different from each other. In order to cover the basics, let us jump into the discussion.


STACK
  •         The Concept           
                            The last stored data will be the first one to go out. It can be executed by utilizing array or linked list. Elements of data are then inserted and deleted only from one point called the top. [For detailed note, Stack can be applied for Reverse the order of data, Convert infix expression into postfix, Convert postfix expression into postfix, Backtracking problem, Recursive function, and conversion of decimals into its binary equivalent.] See the picture below for reference:
Stacks


  •         The Operations           
                            There are 3 main basic operations in Stack, such as:
        • push(x)
                                    Inserting an item 'x' to the top of the stack.
        • pop()
                                    Deleting an item from the top of the stack.
        • top()
                                    Return to the item on the top of the stack.

                            To see how the operations works, see the picture below for reference:


QUEUE
  •         The Concept           
                            The first stored data will be the first one to go out. It can be executed by utilizing array or linked list. Unlike Stacks who has only one end, elements of data in Queue are then inserted at one point called the rear and are deleted from the other one point called the front. [For detailed note, Queue can be applied for Deques, Priority Queues, and Breath First Search.] See the picture below for reference:
Queue
  •         The Operations           
                            There are 3 main basic operations in Queue, such as:
        • push(x)
                                    Inserting an item 'x' to the back of the queue.
        • pop()
                                    Deleting an item from the front of the queue.
        • front()
                                    Return to the item on the most front of the queue.

                         To see how the operations works, see the picture below for reference:

                            That is all the basics about Stack and Queue and how they operate according to their own commands.
- END -


References:
S. Sridhar. 2015. Design and Analysis of Algorithms. Oxford University Press. New Delhi. ISBN: 9780198093695. Chapter 5
Reema Thareja. 2014. Data structures using C. Oxford University Press. New Delhi. ISBN:9780198099307. Chapter 7 & 8
Thomas H. Cormen, Charles E. Leiserson, Ronald L. Rivest, & Clifford Stein. (2009). Introduction to Algorithms. 03. The MIT Press. London. ISBN: 9780262033848. Chapter 10
https://visualgo.net/en/list?slide=4
https://visualgo.net/en/list?slide=5
https://www.geeksforgeeks.org/difference-between-stack-and-queue-data-structures/

Komentar