jawbone Wiki
Collection of essential computer science data structures in Javascript
Brought to you by:
shantibhushan
Welcome to your wiki!
This is the default page, edit it as you see fit. To add a new page simply reference it within brackets, e.g.: [SamplePage].
The wiki uses Markdown syntax.
Essential Data structures in Javascript
Collection of essential computer science data structures in Javascript. Plus some additional nifty datastructures coming in upcoming versions.
Contains basic data structures
Node (aliases UnaryNode)
A simple node structure consisting of
value, and link tonextitem.var a= new Node();var b= new Node();var c= new Node();a.value(1);b.value(2);a.next(b);b.next(null); // [Optional] This is by default// Now traverse the nodes using their linksvar t= a; // Start with first nodewhile(t!== null) {alert(t.value());t= t.next();}Calling
value()without any parameters acts like a getter to read valuesCalling
next()behaves in the same wayBinaryNode
Extension to
Nodegiving access topreviousTernaryNode (alias
TreeNode)Similar to
BinaryNodeexceptnextis referred to asright, andpreviousis referred to asleftPlus some advanced data structures
Stack (aliases
LinkedList,LIFOQueue)Stack is the most basic form of data structure that uses
Nodeand provides a list into which items arepushed on top, andpoped off from top.push,pophappens on same end providing you with a simple LIFO (Last In First Out) list of items. At any time, you can useisEmptyto check is list is empty.Alternatively, you can also use read-only
sizeto determine how many items are currently in the list.Queue (aliases
FIFOQueue)Queue is another basic form of data structure representing a list into which items can be
pushed on one end, andpoped off the other end.This gives you a nice list of items that can be queued for LIFO (Last In First Out) processing.
Similar to
Stack, bothisEmptyandsizeare available.Dequeue (aliases
Deque,Deck)A double-ended queue is an advanced data structure which allows
push,popfrom whichever end you want to.This advanced data structure provides you with a list into which you can
pushFirst, orpushLastand you canpopFirst, orpopLast.To handle complex operations, at anytime you can check
isEmpty, orsizeto determine items in the list for processing.No external dependencies on any other libraries. To use in your page,
<script type="text/javascript" language="javascript" src="core_data_structures-1.0.js"></script>A minified version is available too in case you choose to
<script type="text/javascript" language="javascript" src="core_data_structures-1.0.min.js"></script>Aliases allow you to use user-friendly names to represent these data structures. Few intuitive aliases are already provided. In Javascript, everything is an object, hence you can store & retrieve any type of Javascript object onto the
Stack, orQueue.For advanced ease of use, some synonyms are allowed within these data structures as below
shiftis synonymous topushon aStack,Queueand their aliases.unshiftis synonymous topopon aStack,Queueand their aliases.enqueueis synonymous topushon aQueueand it's aliases.dequeueis synonymous topopon aQueue` and it's aliases.Please feel free to use, suggest, augment as long as you honor the LICENSE.