Home >Common Problem >Compared with the sequential stack, what is the obvious advantage of the chain stack?
Compared with the sequential stack, the advantage of the chain stack is that the stack is usually not full. Because the sequential stack is implemented with an array, the size of the stack must be determined in advance, and the memory usage efficiency is not high, and overflow problems caused by running out of array space cannot be avoided; while the chain stack dynamically applies for memory, so the stack will generally not be full. Condition.
The operating environment of this tutorial: Windows 7 system, Dell G3 computer.
Compared with the sequential stack, the chain stack has an obvious advantage: the stack is usually not full.
Because the sequential stack is implemented with an array, the size of the stack must be determined in advance. The memory usage is not very efficient, and overflow problems caused by running out of array space cannot be avoided; while the chain stack is dynamic because When applying for memory, the stack will generally not be full, but an empty stack will still appear.
Because the chain stack and the sequential stack are both stacks, the stack is first in, last out, and insertion and deletion operations can only be performed on the top of the stack, so the chain stack has no advantage over the sequential stack in insertion and deletion operations.
Stack
Stack, as a data structure, is a special linear table that can only be inserted and deleted 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 a function is called. The stack is used when doing recursion!
The stack plays an important role in the running of the program. The most important thing is that the stack saves the maintenance information required when a function is called, which is often called a stack frame or activity record. Stack frames generally contain the following aspects of information:
1. The return address and parameters of the function
2. Temporary variables: including non-static local variables of functions and other temporary variables automatically generated by the compiler.
For more related knowledge, please visit the FAQ column!
The above is the detailed content of Compared with the sequential stack, what is the obvious advantage of the chain stack?. For more information, please follow other related articles on the PHP Chinese website!