JINI N K
Content
1. INTRODUCTION 2. STACK
3. OPERATIONS ON STACK – PUSH/POP
4. IMPLEMENTATION OF STACK USING LIST
DATA STRUCTURE:
• A 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.
• The basic Python data structures in Python include list,
set, tuples, and dictionary.
• Data structures are “containers” that organize and group
data according to type.
• The data structures differ based on mutability and order.
STACK
STACK
Linear Data structure
Follows LIFO principle
LIFO – Last In First Out
Insertion and Deletion
can occur at only one end,
called the TOP of the stack
STACK TERMINOLOGIES
Peek - Inspecting the value at the stack’s top
without removing it.
Overflow - Trying to push an item when the stack is full
Underflow - Trying to delete/pop an item from an empty
stack
IMPLEMENTING STACK USING LIST
IsEmpty()
Push()
Pop()
Peek()
Display()
FUNCTION TO CHECK STACK IS EMPTY
FUNCTION TO PUSH AN ELEMENT
FUNCTION TO PUSH AN ELEMENT
FUNCTION TO POP AN ELEMENT
FUNCTION TO POP AN ELEMENT
FUNCTION TO PEEK AN ELEMENT
FUNCTION TO DISPLAY
Write PushOn(Book) and Pop(Book) methods/functions
in Python to add a new Book and delete a Book from a list
of Book titles.
Arr is a list of numbers.
Write a function PUSH(Arr), to push all
numbers divisible by 5 from the list Arr to
the stack.
Display the stack if it has at least one
element otherwise display an appropriate
message.
Write a function in Python, Push(Player) where , Player is a
dictionary containing the details of stationary items–
{Game:name}. The function should push the names of those
players into the stack where the name starts with letter ‘R’. Also
display the count of elements pushed into the stack. For
example:
If the dictionary contains the following data:
Players={"Cricket": “RahulDravid”,"Chess": “R Pragnananda “,
"Kho-Kho": “Sarika Kale”, "Kabaddi": “Pardeep Narwal”}
The stack should contain :
RahulDravid
R Pragnananda
The output should be:
The count of elements in the stack is 2
DATA STRUCTURES
- STACK
Type A & Type C
What are data structures? Name some common
data structures .
A data-structure is a logical way for organizing data in memory
such that it can be used efficiently.
Some common data structures are stack, queue, trees, linked
lists etc.
What is a stack?
Stack is a basic data-structure where insertion and deletion of
data takes place at one end called the top of the stack i.e., it
follows the Last In-First Out(LIFO) principle.
Which data structure will you use for simulating a
blanket donation camp?
We can use stack or queue data structure for simulating a blanket
donation camp
What are push and pop operations?
Push – Inserting a new element in a stack
Pop – Deletion of an element in a stack
Give some examples of stack applications
Evaluation of arithmetic expressions
Reverse a data
Type - C
Write a program that depending upon user's choice, either pushes or pops an
element in a stack.
A line of text is read from the input terminal into a stack. Write a program to output the
string in reverse order, each character appearing twice. (e.g., the string a b c d e should be
changed to ee dd cc bb aa)
Write a function in Python POP(Arr), where Arr is a stack implemented by a list of numbers.
The function returns the value deleted from the stack.
Write a program that depending upon user's choice, either pushes or pops an element in a
stack the elements are shifted towards right so that top always remains at 0th (zero) index.
Write a program that depending upon user's choice, either pushes or pops an element in a
stack the elements are shifted towards right so that top always remains at 0th (zero) index.
Write Each node of a STACK contains the following information :
(i) Pin code of a city,
(ii) Name of city
Write a program to implement following operations in above stack
(a) PUSH () To push a node in to the stack.
(b) POP( ) To remove a rode from the stack.
Write PUSH (Books) and POP (Books) methods, in python to add Books and remove
book considering them to act as Push and Pop operations of Stack.
JINI N K