# Stack

## A practical requirement of stack

Please enter an expression formula:`[7*2*2-5+1-5+3-3]`

Click calculate [as shown in the figure below]

Excuse me: how does the bottom layer of the computer calculate to get the result? Note that it’s not a simple list of formulas, because we look at formula 7*2*2 – 5, but how does the computer understand this formula (for the computer, what it receives is a string), we are talking about this problem. ->Stack

## Introduction of stack

- Stack（
`stack`

) - Stack is a first in, then out（
`FILO-First In Last Out`

）An ordered list of. - Stack (
`stack`

）It is a special linear table that restricts the insertion and deletion of elements in a linear table to only be carried out at the same end of the linear table. The end that allows insertion and deletion is called the changing end, which is called the top of the stack（`Top`

）The other end is the fixed end, which is called stack bottom（`Bottom`

)。 - According to the definition of stack, the first element put into the stack is at the bottom of the stack, and the last element put in is at the top of the stack. On the contrary, the last element put in is deleted first, and the first element put in is deleted last
- Out of the stack（
`pop`

）And into the stack（`push`

）The concept of (as shown in the figure)

## Application scenarios of stack

- Subroutine call: before jumping to the subroutine, the address of the next instruction will be stored in the stack until the subroutine is executed, and then the address will be taken out to return to the original program.
- Dealing with recursive calls: similar to subroutine calls, except that in addition to storing the address of the next instruction, parameters, regional variables and other data are also stored in the stack.
- Expression conversion [ Infix expression to suffix expression ] Evaluation and evaluation ( Practical solution )。
- Traversal of binary tree.
- The depth first search method of graph.

`package com.atguigu.stack ;`

This work adoptsCC agreementReprint must indicate the author and the link of this article