What is the best way to implement a Stack and a Queue in JavaScript?
I'm looking to do the shunting-yard algorithm and I'm going to need these data-structures.
What is the best way to implement a Stack and a Queue in JavaScript?
I'm looking to do the shunting-yard algorithm and I'm going to need these data-structures.
If you understand stacks with push() and pop() functions, then queue is just to make one of these operations in the oposite sense. Oposite of push() is unshift() and oposite of pop() es shift(). Then:
Regards,
In Javascript the implementation of stacks and queues is as follows:
Stack: A stack is a container of objects that are inserted and removed according to the last-in first-out (LIFO) principle.
Queue: A queue is a container of objects (a linear collection) that are inserted and removed according to the first-in first-out (FIFO) principle.
Unshift: Method adds one or more elements to the beginning of an array.
Shift: Method removes the first element from an array.
taken from "9 javascript tips you may not know"
No Array(s)