Created
March 7, 2020 06:06
-
-
Save amalgjose/4e369963971da592ee4b44d4a871611b to your computer and use it in GitHub Desktop.
Stack implementation in python using Queue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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