DEV Community

Discussion on: Implementing the Stack Data Structure in Javascript

Collapse
 
lewiscowles1986 profile image
Lewis Cowles

JS comes with stack LIFO and queue FIFO built-in using arrays.

The benefit of using an array instead of linked list? Well it can serialize more trivially given a start pointer and size.

Perhaps something worth considering (although maybe not for JS)

Also JS doesn't have support for explicit pointers, so not sure if it's confusing for people to use that terminology when discussing JS implemented Stack.

Thoughts?

Collapse
 
theoutlander profile image
Nick Karnik

You are right about JS Arrays. I should have mentioned that in the video. I was going to use this as a basis for future videos as we go into linked lists and more interesting data structures.

I think the exercise of building these basic structures will get people familiarized with something they’re already using.

As for pointers, I’ve seen people use that term in JS quite a bit. However, they’re probably not thinking of it in the C++ sense. Am I right about that assumption?

Collapse
 
lewiscowles1986 profile image
Lewis Cowles

I was thinking even the terms pop, push and shift, unshift would come up was all. Personally I think queue, dequeue would be better names but we can't go breaking public API's based on one persons persnickety notions ;-)

It's great you want people to get familiarised, I think that is another benefit to arrays, and certainly your examples will translate better to Java, Python or C.

On pointers, Asm / C with a layer of "my language gives me this" :-).

In CPP I'm currently re-learning for newer language features (supposed to be updating but it turns out I was writing C with classes for years). Basically everything is meant to be a reference unless you're systems-level and need the control / PITA which is manual pointers. So you might as well if you're handling C++ use references and if you need pointers write C (for learners or people not controlling space-vehicles or operating on tiny embedded packages).