js封装栈和队列比其他语言方便
function Stack(){ this.arr=[]; this.push = function(value){ this.arr.push(value); } this.pop = function(){ return this.arr.pop(); } } var stack = new Stack(); stack.push(1); stack.push(2); stack.push(3); console.log(stack.arr); // [ 1, 2, 3 ] stack.pop(); console.log(stack.arr); // [ 1, 2 ] // 队列 function Queue(){ this.arr=[]; this.push = function(value){ this.arr.push(value); } this.pop = function(){ return this.arr.shift(); } } var queue= new Queue(); queue.push(1); queue.push(2); queue.push(3); console.log(queue.arr); // [ 1, 2, 3 ] queue.pop(); console.log(queue.arr); // [ 2, 3 ]
落过的 帅哥美女 如果我哪里说的不全,或者哪里解释错了,希望可以说一下,我马上改,
结束了画个重点吧
重点:走过路过的帅哥美女,点个赞,程序员不嫖程序员┗|`O′|┛ 散会