Python implementation of a python-based------sequential structure queue

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.