Implementation of stack and queue of PYTHON--PYTHON data structure

Source: Internet
Author: User

This is in the official website list support, have realized.

To supplement the stack, the characteristics of the queue:

1. Stack (stacks) is a linear data structure that can only be accessed by accessing the first end of the database, and has the characteristics of the LIFO (last Out,lifo)

2. A queue is a linear data structure with FIFO features, where the addition of elements can only be done at one end, and the deletion of elements can only take place at the other end. The one end of the queue that can increment the element is called the tail of the queue, and the one end of the element is called the team head.

Address in http://docs.python.org/2/tutorial/datastructures.html#more-on-lists, below the official code.

About Stacks
>>>Stack=[3,4,5]>>>Stack.Append(6)>>>Stackappend (7) >>> stack[3, 4, 5, 6, 7]>>> stack pop () 7>>> stack[3, 4, 5, 6]>>> stack. Pop () 6>>> stack.< span class= "n" >pop () 5>>> stack[3, 4]

about the queue
>>>FromCollectionsImportDeque>>>Queue=Deque(["Eric","John","Michael"])>>>Queue.Append("Terry")# Terry arrives>>> queue. Append ( "Graham" ) # Graham arrives >>> queue. Popleft () # the first to arrive now Leaves ' Eric '  >>> queue. Popleft () # the second to arrive now Leaves ' John '  >>> queue # Remaining queue in order of Arrivaldeque ([' Michael ', ' Terry ', ' Graham ']) 

Python--python data structure stack, queue implementation

Related Article

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.