DEV Community

Moya Richards
Moya Richards

Posted on

1 1

Simplifying: Stacks and Queues

Simplifying:  Stacks and Queues

Stacks and queues: this is how I remember them:

Stacks: I picture something vertical: a pile of plates,a bottle.

Queues: I picture something horizontal: a pipe, a line (I join first, I get served first).

Stacks - LIFO:  you can only add(append, push) and remove(pop) from the back(top,end).
Queues - FIFO : add (enqueue,append) to the back(rear), only remove(dequeue,popleft) from the front .
Enter fullscreen mode Exit fullscreen mode

LIFO : Last in, first out.
FIFO : first in, first out.

If you are JavaScript developer, you are unconsciously working with stacks and queues everyday:

  • You use stacks every time you run your code: "function call stack".
  • You use queues every time you run asynchronous code: "The event queue" of the event loop.

Here are some examples of stacks and queues in the real world:

Stack:

  • Your favorite text editor: undo/redo feature.
  • Backtracking: your browsers "back" button.
  • Reverse : try to reverse your name.

Queue:

  • Order processing: you stand 6 feet apart from everyone as you wait in line to place your order with a cashier.
  • Message processing: your long SMS messages are stored in a queue( messages are sent in the order they are received). Test this feature out on twitter by exceeding your 143 character limit

Now, how have you used stacks and queues consciously in your career?

Let's talk about your usage of these data structures or concepts in your projects.
Enter fullscreen mode Exit fullscreen mode

Sentry blog image

How to reduce TTFB

In the past few years in the web dev world, we’ve seen a significant push towards rendering our websites on the server. Doing so is better for SEO and performs better on low-powered devices, but one thing we had to sacrifice is TTFB.

In this article, we’ll see how we can identify what makes our TTFB high so we can fix it.

Read more

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs