Skip to content

Instantly share code, notes, and snippets.

@amalgjose
Created March 7, 2020 06:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save amalgjose/4e369963971da592ee4b44d4a871611b to your computer and use it in GitHub Desktop.
Save amalgjose/4e369963971da592ee4b44d4a871611b to your computer and use it in GitHub Desktop.
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