Stack and queue of data structures

Source: Internet
Author: User

Stacks and queues are special linear tables.

Stack: Only allow data to be added and deleted at one end, there is the principle of FIFO.

Inserting elements into the stack, removing elements from the top of the stack as a stack. The bottom element of the stack is the top element of the stack, and the top element of the stack is the top element.

Stacks are only allowed to increment and delete elements at the top of the stack.

The first-in-stack elements are at the bottom of the stack, and then on top of the stack.

Stacks can be implemented in the form of arrays. The stack is a restricted linear table, allowing only the deletion of elements at the top of the stack, insert operations.

Link Stacks:

The previous element's next point points to the element that was originally on top of the stack, and so on until the bottom of the stack.

Into the stack operation:

The stack operation:

Java inside the stack implementation:

Stack, an array-based sequential stack implementation, thread-safe.

LinkedList: is a double-line linked list structure, also has the operation of the stack, is the chain implementation of the stack, thread is unsafe.

Queue:

Specifies the direction in which data is entered and the direction to go, and the data in the queue is always first entered first.

The queue only allows elements to be deleted at the front end, and elements inserted on the backend.

Loop queue:

A queue that is connected to the end, the last element next to the first element.

The chained storage structure and implementation of the queue:

Insert Queue:

To remove a queue:

Queues in the Java collection:

After JDK 1.5, the queue interface represents a queue that provides methods for inserting, removing, and accessing.

Arrayblockingqueue,linkedblockingqueue,priorityqueue,concurrentlinkedqueue,synchronusqueue.

Arrayblockingqueue,linkedblockingqueue,concurrentlinkedqueue thread safety.

Two-way queue:

You can delete and insert elements on either side of the queue.

A two-way queue is a special linear table of queues and stacks.

Not finished, waiting for tomorrow to write, sleepy, sleep first

Stack and queue of data structures

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.