Last active
February 24, 2018 21:13
-
-
Save Mahdisadjadi/70090392d9d9ec579a005bb2466ff333 to your computer and use it in GitHub Desktop.
A simple implementation of Queue data structure in python
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
# A simple implementation of Queue data structure in python | |
# FIFO: first (item) in, first (item) out | |
# Insert at the front, pop at the end of the list | |
class Queue(): | |
def __init__(self): | |
self.items = [] | |
def isEmpty(self): | |
return self.items == [] | |
def size(self): | |
# size of the list | |
return len(self.items) | |
def enqueue(self, item): | |
#insert the item in the front of the list | |
self.items.insert(0,item) | |
def dequeue(self): | |
# removes and returns the last item in the list | |
return self.items.pop() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment