Python ADT - Stack
Submit solution
Python
Points:
10
Time limit:
0.04s
Memory limit:
10M
Author:
Problem type
Allowed languages
ADT - Stack
Implement a Stack class in Python with the following operations:
push(item)
: Adds an item to the top of the stack.pop()
: Removes and returns the item from the top of the stack.top()
: Returns the item at the top of the stack without removing it. (it is also referred aspeek()
is_empty()
: Returns True if the stack is empty, False otherwise.size()
: Returns the number of items in the stack.
Testcases
Input 1
18
24
44
Output 1
Item 18 pushed into the Stack
Item 24 pushed into the Stack
Item 44 pushed into the Stack
Top Element is: 44
Stack Size is: 3
Input 2
18
24
44
Output 2
Item 18 pushed into the Stack
Item 24 pushed into the Stack
Item 44 pushed into the Stack
Top Element is: 44
Popped Element is: 44
Top Element is: 24
Input 3
72
Output 3
Is Stack Empty: True
Item 72 pushed into the Stack
Is Stack Empty: False
Comments