Home  >  Article  >  Features of the stack

Features of the stack

(*-*)浩
(*-*)浩Original
2019-06-03 09:26:5045067browse

Characteristics of stack

Stack (Stack) is a linear storage structure, which has the following characteristics:

The data elements in the stack comply with "last in first out" "(First In Last Out) principle, referred to as FILO structure.

Limit that insertion and deletion operations can only be performed on the top of the stack.

Features of the stack

Related concepts of stack:

Top and bottom of stack: The end that allows the insertion and deletion of elements is called the top of the stack, and the other end is called the bottom of the stack. .

Push the stack: The insertion operation of the stack is called pushing, also called stack pushing or pushing.

Popping the stack: The deletion operation of the stack is also called popping the stack.

For example, we have a stack that stores integer elements. We push the stack in sequence: {1,2,3}

Features of the stack

In the process of pushing the stack , the position of the top of the stack keeps moving "upward", while the bottom of the stack is fixed.

If we want to pop elements from the stack:

Features of the stackThe order of popping elements from the stack is 3, 2, 1. The order is opposite to that of pushing into the stack. This is the so-called "first in" "Later out".

During the process of popping the stack, the top position of the stack keeps moving "downward", while the bottom of the stack remains unchanged.

If you have played an educational toy called the Tower of Hanoi, you will know that the access of the small discs in the game is a first-in, last-out order, and a cylinder is a stack:

Stack operations

The common operations of the stack are:

Pop the stack, usually named pop

Push the stack, usually named push

Find the size of the stack

Judge whether the stack is empty

Get the value of the top element of the stack

The storage structure of the stack

Since the stack is a linear structure, it can use an array or linked list (single-way linked list, doubly linked list or circular linked list) as the underlying data structure.

The above is the detailed content of Features of the stack. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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
Previous article:What does dcs mean?Next article:What does dcs mean?