Skip to the editor
JSGroundwork
JSGroundwork handwritten · web dev
←Back to Stacks & queues

Ready to read

JSJavaScript⑂Git◎Interview prepΣDSA in JSSDSystem Design
More topics15›
</>HTML{ }CSS⚛ReactNNext.jsNeNest.jsTSTypeScriptNoNode.js🐳DockerDBSQL & Databases✓Testing🔒Web Security☁Cloud & DevOps◈GraphQL◆Redis☸Kubernetes
☰‹›
Description
All topics›JavaScript›Stacks & queues

Implement Stack using Queues

beginnerlayer B8 · Stacks & queues4 tests

Build a LIFO stack whose only storage is queues. A queue lets you add to the back, remove from the front, and read its length — nothing else.

  • push(x) — put x on top of the stack
  • pop() — remove and return the top value
  • top() — return the top value without removing it
  • empty() — true when the stack holds nothing
  • Do not reach into the middle or the end of the storage — only push (to the back) and shift (from the front)

Stuck?

All exercisesPlayground
1234567891011121314
loading the editor…

Nothing yet — hit Run and whatever you log shows up here.

Submit to see how you did.

⌘/Ctrl + Enter run⌘/Ctrl + S save⌘/Ctrl + / comment⌘/Ctrl + F find/replace⌘/Ctrl + D select next matchAlt + click multi-cursorTab indent · ⇧Tab outdentEsc leave fullscreen