使用javascript使用两个队列构建堆栈

使用javascript使用两个队列构建堆栈,javascript,data-structures,Javascript,Data Structures,有人能告诉我如何用javascript使用两个队列构造堆栈吗?(使用链接列表)。 我可以实现一个堆栈。我可以实现一个队列。但我正在努力弄清楚如何使用队列来构建堆栈 class Stack { constructor() {} push() { } pop() {} } class Node { constructor(value) { this.value = value; this.next = null; }

有人能告诉我如何用javascript使用两个队列构造堆栈吗?(使用链接列表)。 我可以实现一个堆栈。我可以实现一个队列。但我正在努力弄清楚如何使用队列来构建堆栈

class Stack {
    constructor() {}
    push() {

    }
    pop() {}
}

class Node {
    constructor(value) {
        this.value = value;
        this.next = null;
    }
}

class Queue {
    constructor() {
        this.first = null;
        this.last = null;
        this.size = 0;
    }
    enqueue(data) {
        var node = new Node(data);

        if (!this.first) {
            this.first = node;
            this.last = node;
        } else {
            this.last.next = node;
            this.last = node;
        }

        return ++this.size;
    }

    dequeue() {
        if (!this.first) return null;

        var temp = this.first;
        if (this.first == this.last) {
            this.last = null;
        }
        this.first = this.first.next;
        this.size--;
        return temp.value;
    }
}

我希望能够在堆栈上使用push和pop方法。这不是家庭作业什么的。这只是个人发展。如果有人能帮忙的话,我也非常感谢你的一点解释。多谢各位

只要稍作改动,你就可以试试这样的@VLAZ谢谢。这真是helpful@CodeManiac非常感谢你。你是个明星。我现在明白了。再次感谢。只需稍作改动,您就可以尝试这样的@VLAZ谢谢。这真是helpful@CodeManiac非常感谢你。你是个明星。我现在明白了。再次感谢。