stack and queue

Linear table

Definition: A finite sequence of zero or more data elements

A linear list is a type of data structure, a linear list is a finite sequence of n data elements with the same characteristics

It is a sequence, and the elements are in order. If there are multiple elements, the first element has no predecessor, the last element has no successor, and each other element has only one predecessor and successor

The actual storage method of the linear table is divided into two implementation models
  1. Sequence table The
    sequence table stores elements sequentially in a continuous storage area__:Continuous storage__
  1. Linked list
    Stores elements in a series of storage blocks constructed by linking__:Distributed storage__

stack [FILO]

understanding of stack

A stack is a container, a restricted linear list __[first in, last out]__, which can be implemented by a sequential list or a linked list

Features

Only allow data operations at one end of the container__:[Top:Top of the container] : [Add data to the top of the stack: Push, output data from the top of the stack: Pop]__, first in, last out , the default operation is the last stored in the previous an element

[========]

queue [FIFO]

understanding of queues

A queue is a container, a restricted linear list __[first in, first out]__, which can be implemented with a sequential list or a linked list

Features:

A linear list that only allows insertion operations at one end __[the tail of the queue] and deletes [the head of the queue]__ operations at the other end, and operations in the middle are not allowed

[========]

Similarities between stacks and queues:

1. Both are linear structures.
2. Insert operations are limited to the end of the table.
3. Both can be realized by sequential structure and chain structure. ,
4. The time complexity of insertion and deletion is O(1), and the space complexity is the same for both.
5. The management mode of multi-chain stack and multi-chain queue can be the same.

[========]

The difference between stack and queue:

1. The location of deleting data elements is different. The deletion operation of the stack is performed at the end of the table, and the deletion operation of the queue is performed at the head of the table.
2. Different application scenarios;

stack:

Common application scenarios of stack include solving bracket problem, expression conversion and evaluation, function call and recursive implementation, depth-first search traversal, etc.;

queue:

Common application scenarios of queues include management of various resources in computer systems, management of message buffers, and breadth-first search traversal.
3. The sequential stack can realize multi-stack space sharing, while the sequential queue cannot.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325196467&siteId=291194637