Skip to content

Instantly share code, notes, and snippets.

@d-rat
Created March 24, 2022 07:32
Show Gist options
  • Select an option

  • Save d-rat/0da1cd8ba6c174e7f725873fdf1a2efa to your computer and use it in GitHub Desktop.

Select an option

Save d-rat/0da1cd8ba6c174e7f725873fdf1a2efa to your computer and use it in GitHub Desktop.

Revisions

  1. d-rat created this gist Mar 24, 2022.
    24 changes: 24 additions & 0 deletions queueStack.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,24 @@
    class QueueStack {
    constructor() {
    this.q = [];
    }
    push(val) {
    let size = this.q.length;
    this.q.push(val);
    while (size--) {
    this.q.push(this.q.shift());
    }
    }
    pop() {
    if (!this.q.length) return null;
    return this.q.shift();
    }
    peek() {
    if (!this.q.length) return null;
    return this.q[0];
    }

    isEmpty() {
    return this.q.length === 0
    }
    }