Showing posts with label deque. Show all posts
Showing posts with label deque. Show all posts

Friday, July 03, 2009

No Peeking in the Javascript Deque

Another (previous) take on the Javascript Deque with more of a Crockford creation style preventing messing with the Deque's internals. Create one without using new - "var d = deque();", enjoy:

Wednesday, July 01, 2009

Javascript Deque

Doubly ended queue code is just a whole lot cleaner if you go with dummy head and tail nodes to avoid special cases. I put together this Javascript example: A Javascript array has the methods available (push(), pop(), shift(), unshift()) to be used as a deque but of course being an array you shouldn't be adding and removing from anywhere but the tail end if you need top performance. The following provides for a comparison between my deque and a regular Javascript array for adding and removing items from the head or tail of the data structure.
Items:
array dequeue
head tail