Stack stack

Time:2022-5-10

Application scenario: first in and last out

For example: converting decimal to binary, judging whether the parentheses of string are valid, and function call stack

Determine whether the parentheses of the string are valid

((()) -va

(((()())) -inva

*The more backward the left bracket, the more forward the corresponding right bracket

*The left bracket goes into the stack and the right bracket goes out of the stack. Finally, when the stack is empty, it is legal

Function call stack

*The last called function is executed first.

*The JS interpreter uses the stack to control the calling order of functions.

function greetinh(){
  sayHi()  
}
function sayHi(){
  return 'hi'
}

greetinh()

In this function call example, greetinh () is called first, but it is finally executed.