Linking Those Lists

with JavaScript

Objectives

at the end of this lesson, you will be able to

  • describe what a linked-list is
  • create a linked list with javascript

What is a linked list?

  • Singly linked lists contain nodes which have a data field as well as a 'next' field, which points to the next node in line of nodes.
  • In a 'doubly linked list', each node contains, besides the next-node link, a second link field pointing to the 'previous' node in the sequence

Singly linked list

var singlyLinkedList = {
    data: 'Julia Childs',
    next: {
        data: 42,
        next: {
            data: 'footer',
            next: null
        }
    }
};

Doubly linked lists

var node1 = {data: 'this is node 1', next: null, pre: null};
var node2 = {data: 'this is node 2', next: null, pre: null};
var node3 = {data: 'this is node 3', next: null, pre: null};

node1.next = node2;

node2.prev = node1;
node2.next = node3;

node3.prev = node2;

Methods

  • insert
  • delete

For more reading

https://en.wikipedia.org/wiki/Linked_list#Singly_linked_list

Questions?

linked lists

By Brooks Patton

linked lists

All about linking those lists with javascript

  • 1,017