paint-brush
Implement Queue using Stacksby@deft
503 reads
503 reads

Implement Queue using Stacks

by Sergey Golitsyn4mSeptember 28th, 2022
Read on Terminal Reader
Read this story w/o Javascript
tldt arrow

Too Long; Didn't Read

Sergei Golitsyn proposes a first in first out (FIFO) queue using only two stacks. The main trick will be in **pop** and **peak** operations. For pop operation, we have to move all elements from the current stack to the tmp stack. If **tmp** stack contains an element we can simply return an element from this stack. The problem is simple and clear, just add an element into the stack. For pop, we need to move an element to the next stack and return it.

Coin Mentioned

Mention Thumbnail
featured image - Implement Queue using Stacks
Sergey Golitsyn HackerNoon profile picture
Sergey Golitsyn

Sergey Golitsyn

@deft

Senior Software Engineer with 7+ YoE building massively scalable systems both from scratch and diving into a codebase

About @deft
LEARN MORE ABOUT @DEFT'S
EXPERTISE AND PLACE ON THE INTERNET.
0-item

STORY’S CREDIBILITY

DYOR

DYOR

The writer is smart, but don't just like, take their word for it. #DoYourOwnResearch

L O A D I N G
. . . comments & more!

About Author

Sergey Golitsyn HackerNoon profile picture
Sergey Golitsyn@deft
Senior Software Engineer with 7+ YoE building massively scalable systems both from scratch and diving into a codebase

TOPICS

THIS ARTICLE WAS FEATURED IN...

Permanent on Arweave
Read on Terminal Reader
Read this story in a terminal
 Terminal
Read this story w/o Javascript
Read this story w/o Javascript
 Lite