Source: http://blog.seclibs.com/ Data
In the last article, stack can be divided into sequential stack and chain stack.
Sequential stack: stack implemented by array
Chain stack: a stack implemented with a linked list
Because the stack is a sort of “function limited” sequential list, so in the implementation, the effect can be achieved by modifying the previous array and linked list.
Sequential stack
In order to better represent the top element of the stack when implementing the sequential stack, I replaced the used number used in the previous array with top, and there was no significant change in other aspects.
To download the code, please move to the end of the article.
Chain stack
On the basis of the original linked list, the chain stack saves a lot of contents, such as inserting by position, deleting the specified contents, etc. These are all decided by the characteristics of the stack, which can only be inserted and deleted from one end. Because of this, it is not very meaningful to use double linked list when modifying on the basis of single linked list.
To download the code, please move to the end of the article.
code:
Sequence stack: GitHub
Chain stack: GitHub
First official account and personal blog
Official account: mindless sleepwalking (wuxinmengyi)
Blog: http://blog.seclibs.com/
Security library: http://www.seclibs.com/