Home > Common Problem > What is the storage structure of the stack?

What is the storage structure of the stack?

coldplay.xixi
Release: 2023-02-13 14:28:34
Original
11599 people have browsed it

The storage structure of the stack is a "linear storage structure"; the stack, like the sequence list and the linked list, is a linear storage structure used to store data with a "one-to-one" logical relationship, and is a "special" Linear storage structures are divided into sequential stacks and chain stacks; the stack stores data according to the last-in-first-out principle. 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, it is popped from the top of the stack. Data; 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.

What is the storage structure of the stack?

#The operating environment of this article: Windows 7 system, Dell G3 computer.

The storage structure of the stack:

The stack is the same as the sequence list and the linked list. The stack is also a linear storage structure used to store data with a "one-to-one" logical relationship.

The specific implementation of the stack

The stack is a "special" linear storage structure, so the specific implementation of the stack has the following two methods:

  • Sequential stack: The sequential storage structure can be used to simulate the characteristics of stack storage data, thereby realizing the stack storage structure;

  • Chain stack: The chain storage structure is used to realize the stack structure;

The stack storage structure is different from the linear storage structure learned before. This is because the stack has special requirements for the process of "storing" and "retrieving" data:

  • The stack can only access data from one end of the table, and the other end is closed;

  • In the stack, whether you are storing or retrieving data, you must follow " The principle of "first in, last out" means that the element that is put on the stack first is popped out last.

  • Usually, the open end of the stack is called the top of the stack; correspondingly, the closed end is called the bottom of the stack. Therefore, the element at the top of the stack refers to the element closest to the top of the stack.

Related introduction:

To understand this concept, we must first understand the original meaning of "stack", so that we can grasp the essence. A stack is a place for storing goods or providing accommodation for passengers. It can be extended to a warehouse or a transfer station. Therefore, when it is introduced into the computer field, it refers to a place where data is temporarily stored, so there are terms of stacking and stacking.

First of all, reading and inserting data content in the system or data structure stack (push) and popping are two different things. Pushing is to add data, and popping is to delete data. These operations can only be performed from the top of the stack, which is the interface interface with the lowest address as a constraint. However, reading the data in the stack is casual, and there is no interface constraint. Many people misunderstand this concept and are confused about the stack. The system stack also serves as a media area for cross-component interaction in the computer architecture, that is, the communication channel between the CPU and the memory. The CPU only linearly reads execution instructions from the stack entry specified by the system for the application program we write. , using an image word to describe it is pipeline (pipeline, assembly line). For details on the internal interaction of the CPU, see the introduction to the concepts of EU and BIU.

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 last-in-first-out principle. 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.

The stack can be used to store breakpoints when functions are called. The stack is used when doing recursion.

The above definition is explained in classical computer science.

Related free learning recommendations: php programming (video)

The above is the detailed content of What is the storage structure of the stack?. 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