Data structure foundation-stack

Features of the stack

  • First in last out

Use array to simulate stack in JS

// 栈——数据结构
// 在JS中使用数组来模拟栈
const stack = [];
// 入栈使用push
stack.push(1);   // 1比2先入栈
stack.push(2);
// 出栈使用pop()
const item1 = stack.pop();
const item2 = stack.pop();

Guess you like

Origin blog.csdn.net/sinat_41696687/article/details/115264643