数据结构基础——栈

栈的特点

  • 先进后出

JS中使用数组模拟栈

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

猜你喜欢

转载自blog.csdn.net/sinat_41696687/article/details/115264643