Simple Linked List example JavaSript

// items of the list
var bird = {name:'Mockingbird'};
var cat = {name:'Keyboard'};
var dog = {name:'Fort'};
var duck = {name:'Scrooge'};

// the linked-list itself
var animals = {
    head : bird
};

// each item of the list stores a reference to the next one
bird.next = cat;
cat.next = dog;
dog.next = duck;

// output
var animal = animals.head;
while (animal) {
    console.log(animal.name);
    animal = animal.next;
}

source: http://blog.millermedeiros.com/linked-lists/

One Response to “Simple Linked List example JavaSript”

  1. 3d architectural design software Says:

    3d architectural design software

    alexyz» Blog Archive » Simple Linked List example JavaSript

Leave a Reply

You must be logged in to post a comment.