Skip to content

Commit

Permalink
Created code to implement stack using list in python
Browse files Browse the repository at this point in the history
Signed-off-by: Razor-5 <[email protected]>
  • Loading branch information
Razor-5 committed Oct 18, 2022
1 parent ae8160c commit 14b8f51
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions OperationOfStack.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Python program to demonstrate stack implementation using list
stack = []
#append() function to push element in the stack
stack.append('a')
stack.append('b')
stack.append('c')

print('Initial stack')
print('stack')

# pop() function to pop element form stack in LIFO order
print('\nElements popped from stack:')
print(stack.pop())
print(stack.pop())
print(stack.pop))

print('\nStack after elements are popped:')
print(stack)
# uncommenting print(stack.pop())
#will cause an IndexError as the stack is now empty

0 comments on commit 14b8f51

Please sign in to comment.