A cue is the first thing you put in and the first thing you put out. (= first in first out) It is realized by python.
# -*- coding: utf-8 -*-
class Queue(object):
def __init__(self):
self.queue_list = []
def enqueue(self, value):
self.queue_list.append(value)
def dequeue(self):
try:
#Extract the beginning
value = self.queue_list.pop(0)
except IndexError:
value = None
return value
if __name__ == '__main__':
queue = Queue()
queue.enqueue("a")
queue.enqueue("b")
queue.enqueue("c")
print queue.dequeue()
print queue.dequeue()
print queue.dequeue()
print queue.dequeue()
Execution result % python queue.py a b c None
Recommended Posts