Skip to content

Instantly share code, notes, and snippets.

@amalgjose
Created March 7, 2020 06:06
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Embed
What would you like to do?
Stack implementation in python using Queue
from queue import LifoQueue as lq
# Initializing a stack with max size as 2
sample_stack = lq(maxsize=2)
# The qsize() function shows the size of the stack
print(sample_stack.qsize())
# Now lets push some elements to stack
# put() will push elements to stack
sample_stack.put('edward')
sample_stack.put('sabitha')
# Retrieve the elements from the stack
print('\nRetrieved elements from Stack in LIFO order')
print(sample_stack.get())
print(sample_stack.get())
print("\nIs the stack empty ? : ", sample_stack.empty())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment