Data structures and Algorithms (3)-----> Queues and Stacks

Source: Internet
Author: User

1. Basic properties of stacks and queues

  1. Stack is advanced after out; (like a bullet clip, a last-shot first)
  2. Queues are FIFO; (like waiting in line to buy ice cream, in order to take turns)
  3. Stack and queue in the implementation of the structure can have an array and a list of two forms;

(1) The array structure is easy to implement;

(2) The structure of the linked list is more complicated, because it involves a lot of pointer operation;

1.1 Basic operation of stack structure

(1) Pop operation; (eject)

(2) Top or peek operation;

(3) Push operation; (press stack)

(4) Size operation;

1.2 Basic operations of the queue

(1) The basic operation of the queue differs from the stack operation in that thepush operation joins the element in the team header, while the pop operation pops an element from the tail of the queue;

(2) The basic operation of the queue and stack is the operation of the Time Complexity O (1);

Special:

  1. Two-terminal queue structure: For the end can be pressed into and eject elements;
  2. Priority Queue structure: Determines the popup order of elements based on the priority value of the element, which is essentially a heap structure, not a linear structure;

Data structures and Algorithms (3)-----> Queues and Stacks

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.