Q-Write a python function to:
1. Insert an element at the top of the stack
2. Delete an element at the top of the stack
3. Display the stack elements
4. Inspect an element
Answers
Answer:
Consider the following SpecialStack
16 --> TOP
15
29
19
18
When getMin() is called it should
return 15, which is the minimum
element in the current stack.
If we do pop two times on stack,
the stack becomes
29 --> TOP
19
18
When getMin() is called, it should
return 18 which is the minimum in
the current stack.
Concept:
A function in Python is a collection of connected statements that carry out a certain activity. Functions assist in segmenting our programme into manageable, modular portions. Our programme becomes more organised and controlled as it gets bigger and bigger. It also makes the code modular and prevents repetition.
Given:
insert an element at the top of the stack
Delete an element at the top of the stack
Display the stack elements
Inspect an element
Find:
We are asked to write python functions
Solution:
To add items to the head of the queue, use append().
The object at the head of the queue is removed by the pop() function, which takes no parameters.
All of the stack's items are displayed using the display() method.
The inspect module aids in verifying the existence of the objects in the code we have written. The inspect module is highly helpful in examining certain modules or specific objects because Python is an OOP dialect and all written code is essentially an interaction between any of these things.
Hence a function in Python is a collection of connected statements that carry out a certain activity.
#SPJ2