Data Structures - Stack - Day 4
Data Structures - Stack - Day 4
Data Structures - Stack - Day 4
• A stack is a data structure that allows adding and removing elements according to the Last-In First-
Out (LIFO) principle. Every time an element is added, it goes on the top of the stack; the only
element that can be removed is the element that was at the top of the stack.
Differentiate between Push and Pop operations in the context of stacks. Compt 2022
Pavithra
Write the definition Karthik
of a user defined function PushNV(N) which accepts a list of strings in the parameter N and
pushes all strings which have no vowels present in it, into a list named NoVowel.
● Write a program in Python to input 5 Words and push them one by one into a list named All.
The program should then use the function PushNV() to create a stack of words in the list NoVowel so that it
stores only those words which do not have any vowel present in it, from the list All.
Thereafter, pop each word from the list NoVowel and display the popped word. When the stack is empty, display
the message
"EmptyStack".
For example:
If the Words accepted and pushed into the list All are
['DRY', 'LIKE', 'RHYTHM', 'WORK', 'GYM’]
Then the stack NoVowel should store
['DRY', 'RHYTHM', 'GYM']
And the output should be displayed as
GYM RHYTHM DRY EmptyStack
Pavithra Karthik
Pavithra Karthik
●Write the definition of a user defined function Push3_5(N) which accepts a list of
integers in a parameter N and pushes all those integers which are divisible by 3 or
divisible by 5 from the list N into a list named Only3_5.
●Write a program in Python to input 5 integers into a list named NUM. The program
should then use the function Push3_5() to create the stack of the list Only3_5. There
after pop each integer from the list Only3_5 and display the popped value. When the
list is empty, display the message "StackEmpty".
Pavithra Karthik
Pavithra Karthik
Write separate user defined functions for the following : 3 Compt 2022