0% found this document useful (0 votes)
25 views

CH Datastructure Stack

A stack is a linear data structure that follows LIFO (Last In First Out) order, where elements can only be inserted or removed from one end called the top. In Python, a stack can be implemented using a built-in list, with append() to push elements onto the top and pop() to remove elements from the top. Common applications of stacks include expression evaluation, parenthesis checking, and string reversal. Key operations on a stack include push, pop, peek, size, isEmpty, and isFull.

Uploaded by

Uma TNA
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
25 views

CH Datastructure Stack

A stack is a linear data structure that follows LIFO (Last In First Out) order, where elements can only be inserted or removed from one end called the top. In Python, a stack can be implemented using a built-in list, with append() to push elements onto the top and pop() to remove elements from the top. Common applications of stacks include expression evaluation, parenthesis checking, and string reversal. Key operations on a stack include push, pop, peek, size, isEmpty, and isFull.

Uploaded by

Uma TNA
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

DATA STRUCTURE - STACK

 Data Structure is a named group of data of different data types which is


stored in a specific way and can be processed as a single unit. A Data
Structure has well-defined operations, behavior and properties.
 Python has implicit support for Data Structures which enable you to store
and access data. These structures are called List, Dictionary, Tuple and Set.
 Python allows its users to create their own Data Structures enabling them to
have full control over their functionality. The most prominent Data
Structures are Stack, Queue, Tree, Linked List.

Stack

 A Stack is a linear Data Structure implemented in LIFO (Last In First Out)


manner.
 Insertions and deletions both operations occur only at only one end known
as TOP
 We can create a Stack in python using the built-in List Data Structure which
comes with methods to simulate Stack

To implement a Stack, we need two simple operations:

 push - It adds an element to the top of the Stack.


 pop - It removes an element from the top of the Stack.
Applications of Stack

• Expression Evaluation
• Expression Conversion
• Parenthesis Checking
• String Reversal
• Function Call
Operations on Stack
 The Stack supports the following standard operations:
 push: Pushes an item at the top of the Stack. It returns an error if the
Stack is overflow.
 pop: Remove and return the item from the top of the Stack. It
produces an error if the Stack is appeared to be underflow.
 peek: Returns the item at the top of the Stack without removing it.
 size: Returns the total number of items in the Stack.
 isEmpty: Checks whether the Stack is empty.
 isFull: Checks whether the Stack is full

Overflow: Overflow refers to condition when one tries to PUSH an item in Stack
which is full already

Underflow: Underflow refers to condition when one tries to POP an item from an
empty Stack

Implementation of Stack

 The implementation of Stack using list in Python program is the easiest of


all programming languages.
 It offers a convenient set of methods to operate lists as Stack.
 Python’s built-in Data Structure list can be used as a Stack. Instead of
push(), append() is used to add elements to the top of the Stack while pop()
removes the element in LIFO order

Key Words:

 Postfix notation refers when operator is placed after its operands e.g. ab+
 Prefix notation refers when operator is placed before its operands e.g. +ab.
 Infix notation refers when operator is placed between its operands e.g. a+b.
 While conversion of an Infix notation to its equivalent Prefix/Postfix
notation, only operators are Pushed onto the Stack
 Nested lists: When one or more elements of list is another list, it is called a
nested list.

You might also like