Skip to content

Instantly share code, notes, and snippets.

@Mahdisadjadi
Last active February 24, 2018 21:13
Show Gist options
  • Save Mahdisadjadi/70090392d9d9ec579a005bb2466ff333 to your computer and use it in GitHub Desktop.
Save Mahdisadjadi/70090392d9d9ec579a005bb2466ff333 to your computer and use it in GitHub Desktop.
A simple implementation of Queue data structure in python
# 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