Created
March 24, 2022 07:32
-
-
Save d-rat/0da1cd8ba6c174e7f725873fdf1a2efa to your computer and use it in GitHub Desktop.
Revisions
-
d-rat created this gist
Mar 24, 2022 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal 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 } }