Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Introduction to stack

Sponsored · Your Podcast. Everywhere. Effortlessly. Share. Educate. Inspire. Entertain. You do you. We'll handle the rest. →
Avatar for Pallavi Nasalapure Pallavi Nasalapure
September 15, 2026
2

Introduction to stack

Introduction to stack and its operation

Avatar for Pallavi Nasalapure

Pallavi Nasalapure

September 15, 2026

Transcript

  1. Introduction  Stack is a linear data structure where elements

    are stored in the LIFO (Last In First Out) principle where the last element inserted would be the first element to be deleted.  A real-world stacks, for example − a pack of cards or a pile of plates, etc.
  2. The following diagram depicts a stack and its operations −

     A stack allows all data operations at one end only. At any given time, we can only access the top element of a stack.  Stack uses pointers that always point to the topmost element within the stack, hence called as the top pointer.
  3. Basic Operations on Stacks The most fundamental operations in the

    stack ADT include: push(), pop(), peek(), isFull(), isEmpty(),display().  Working of Stack Data Structure The operations work as follows:  A pointer called TOP is used to keep track of the top element in the stack.  When initializing the stack, we set its value to -1 so that we can check if the stack is empty by comparing TOP == -1.  On pushing an element, we increase the value of TOP and place the new element in the position pointed to by TOP.  On popping an element, we return the element pointed to by TOP and reduce its value.  Before pushing, we check if the stack is already full  Before popping, we check if the stack is already empty 
  4. Stack Insertion: push()  The push() is an operation that

    inserts elements into the stack. The following is an algorithm that describes the push() operation in a simpler way
  5. Stack Deletion: pop()  The pop() is a data manipulation

    operation which removes elements from the stack. The following pseudo code describes the pop() operation in a simpler way.
  6. Retrieving topmost Element from Stack: peek()  The peek() is

    an operation retrieves the topmost element within the stack, without deleting it. This operation is used to check the status of the stack with the help of the top pointer.
  7. Stack is full: isFull()  The isFull() operation checks whether

    the stack is full. This operation is used to check the status of the stack with the help of top pointer.
  8. Stack is empty: isEmpty()  The isEmpty() operation verifies whether

    the stack is empty. This operation is used to check the status of the stack with the help of top pointer.