Home > Common Problem > Are stacks and queues non-linear data structures?

Are stacks and queues non-linear data structures?

青灯夜游
Release: 2020-10-13 13:32:39
Original
17402 people have browsed it

Stacks and queues are not non-linear data structures. Stacks and queues are linear logical structures. The stack is a linear table with limited operations. It is a linear table that is limited to insertion and deletion operations only at the end of the table; queue It is a special linear table that only allows deletion operations at the front end of the table and insertion operations at the back end of the table.

Are stacks and queues non-linear data structures?

Stack (stack) Also known as stack, it is a linear table with limited operations. A linear table that restricts insertion and deletion operations only to the end of the table. This end is called the top of the stack, and the other end is called the bottom. Inserting a new element into a stack is also called pushing, pushing or pushing. It is to put the new element on top of the top element of the stack, making it a new top element; deleting elements from a stack is also called popping or pushing. Pop off the stack, which deletes the top element of the stack and makes its adjacent elements the new top element of the stack.

Stack, as a data structure, is a special linear table that can only perform insertion and deletion operations at one end. It stores data according to the principle of first in, last out. The data that enters first is pushed to the bottom of the stack, and the last data is on the top of the stack. When data needs to be read, data is popped from the top of the stack (the last data is read out first). The stack has a memory function. During insertion and deletion operations on the stack, there is no need to change the bottom pointer of the stack.

A stack is a special linear list that allows insertion and deletion operations at the same end. The end that allows insertion and deletion operations is called the top of the stack, and the other end is the bottom. The bottom of the stack is fixed, and the top of the stack floats. When the number of elements in the stack is zero, it is called an empty stack. Insertion is generally called PUSH, and deletion is called popping (POP). Stack is also called first-in-last-out list.

Queue is a special linear table. The special thing is that it only allows deletion operations at the front end of the table (front) and insertion at the back end (rear) of the table. Operations, like a stack, a queue is a linear list with restricted operations. The end that performs the insertion operation is called the tail of the queue, and the end that performs the deletion operation is called the head of the queue. When there are no elements in the queue, it is called an empty queue.

The data elements of the queue are also called queue elements. Inserting a queue element into the queue is called enqueuing, and deleting a queue element from the queue is called dequeuing. Because the queue only allows insertion at one end and deletion at the other end, only the element that enters the queue earliest can be deleted from the queue first, so the queue is also called a first-in-first-out (FIFO—first in first out) linear list.

The above is the detailed content of Are stacks and queues non-linear data structures?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template