题目描述
用两个栈来实现一个队列,完成队列的Push和Pop操作。 队列中的元素为int类型。
代码
思路:队列是先进先出的结构,所以可以直接使用JavaScript的数组类型来实现。
var result=[];
function push(node)
{
// write code here
result.push(node)
}
function pop()
{
// write code here
return result.shift()
}
用两个栈来实现一个队列,完成队列的Push和Pop操作。 队列中的元素为int类型。
思路:队列是先进先出的结构,所以可以直接使用JavaScript的数组类型来实现。
var result=[];
function push(node)
{
// write code here
result.push(node)
}
function pop()
{
// write code here
return result.shift()
}