100% found this document useful (1 vote)
503 views

Data Structure (Stack) Notes by Nitin Paliwal

Uploaded by

apoilaitonjam.08
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
503 views

Data Structure (Stack) Notes by Nitin Paliwal

Uploaded by

apoilaitonjam.08
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Page 1

NITIN PALIWAL
Page 2

DATA STRUCTURE

A data structure defines a mechanism to store, organise and access data along with
operations (processing) that can be efficiently performed on the data.

STACK

Introduction to Stack
 Analogous to piles of books or plates at home.
 New items are added to and removed from the top of the pile.
 Conventional to add/remove objects only from the top due to
convenience.
 This linear order of arrangement is termed as a stack.

Last-In-First-Out (LIFO) Principle


 Follows the principle of LIFO.
 The most recently inserted element will be the first one to be removed.
 In a stack, the element inserted last is at the top and is the first one to
be taken out.

APPLICATIONS OF STACK

Real-Life Applications
 Piles of clothes in an almirah.
 Vertical stacks of chairs.
 Bangles worn on the wrist.
 Piles of boxes of eatables in a pantry or kitchen shelf.

Programming Applications
 String Reversal: Easily achieved by placing characters of a
string in a stack and retrieving them in reverse order.
 Text/Image Editing: Stack keeps track of changes made,
enabling redo/undo functionalities in text/image editors.
 Web Browsing: Back button functionality in browsers is
implemented using a stack to maintain the history of visited web
pages.
 Arithmetic Expressions: Used to handle matching of
parentheses in arithmetic expressions, ensuring proper nesting
and throwing errors for mismatched parentheses.

NITIN PALIWAL
Page 3

OPERATIONS ON STACK

Stack Fundamentals
 Stack implements Last-In-First-Out (LIFO) arrangement.
 Elements are added to and deleted from one end, termed as the TOP
of the stack.

Key Operations
 PUSH: Adds a new element at the top of the stack.
 Insertion operation.
 Continues until the stack is full, resulting in an 'overflow'
exception if attempted beyond capacity.
 POP: Removes the topmost element of the stack.
 Deletion operation.
 Continues until the stack is empty, resulting in an 'underflow'
exception if attempted on an empty stack.

IMPLEMENTATION OF STACK

Creating an Empty Stack:

NITIN PALIWAL
Page 4

To check whether the stack is empty or not:

To insert a new element in the stack:

To find the number of elements

NITIN PALIWAL
Page 5

To read the most recent element:

To remove the topmost element from stack:

NITIN PALIWAL

You might also like