Java教程

关于栈和队列的进出

本文主要是介绍关于栈和队列的进出,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

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′|┛ 散会

这篇关于关于栈和队列的进出的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!