Stack

Introduction to the data type stack. The stack is an abstract data type of defined operations. In this lesson, we will learn about the stack and its applications. We will also do some programming exercises to help you understand the concept through practice.

We'll cover the following...

The stack is an abstract data type with the following operations:

  • Push(value): Add a value into the underlying collection.
  • Pop(): Remove the most recently pushed value from the collection.
  • Top(): Get the most recent key without removing it from the collection.

    All the above operations are completed in O(1) time.

  • We can think of the stack as a pile of elements. Elements can be added to the top of the pile. To extract any element, we have to remove the elements on top of it.

    The stack is also known as the Last In First Out (LIFO) data structure meaning that the element inserted last is the one that comes out first.

    %0 node_1598803825783 71 node_1598803858756 11 node_1598803869169 9 node_1598803876526 8 node_1598803904340 6 node_1 1 top_node top node_1->top_node
    LIFO data structure: The stack has 6 elements; 1 is the top;

    Applications of the stack

    The following are ...