媒介:
还记得当初用C言语写种种数据结构的苦逼时期嘛,然则用JS来完成栈和行列是云云的简朴啊,然则你们真的相识用js模仿栈和行列,就当你们真的很相识了,毕竟是基础知识,我就写几个案例,不喜勿喷
栈
demo1(栈要领):
栈就是先进后出(LIFO),JS就是云云便利push/pop就能够简朴完成栈
var demoArr = new Array();
demoArr.push('111')
demoArr.push('222')
demoArr.push('333')
console.log(demoArr.pop()) // 333
行列
行列是先进先出(FIFO),高3有两种要领完成,shift和push模仿/unshift和pop模仿
demo2(行列要领1)
var demoArr = new Array();
demoArr.push('july');
demoArr.push('deny');
demoArr.push('mirok'); //demoArr = ['july', 'deny', 'mirok'],按先进先出,出来的则是july
console.log(demoArr.shift()) // july
demo2(行列要领2)
var demoArr = new Array();
demoArr.unshift('july')
demoArr.unshift('deny')
demoArr.unshift('mirok')
console.log(demoArr.pop()) //july