Queue: FIFO, first-out linear table, only allowed in a segment and removed at the other end
The following is a Python implementation
1 #-*-coding:utf-8-*-2 #python implementations of sequential storage queues3 4 classQueue (object):5 def __init__(self,length):6Self.queue = []7Self.length =length8 9 Ten defEn_queue (self,e): One #determine if the queue is full, delete the first entry, and insert a new element into the tail A ifLen (self.queue) >=self.length: - delSelf.queue[0] - Self.queue.append (e) the Else: - Self.queue.append (e) - defDe_queue (self): - ifLen (self.queue): + delSelf.queue[0] - Else: + Print("error, queue is empty") A atQ = Queue (4) -Q.en_queue (1) - Print(Q.queue) - -Q.en_queue (2) - Print(Q.queue) in -Q.en_queue (3) to Print(Q.queue) + -Q.en_queue (4) the Print(Q.queue) * $ Panax NotoginsengQ.en_queue (5) - Print(Q.queue) the + Q.de_queue () A Print(Q.queue)
Python implementation of a python-based------sequential structure queue