1.6.4 • Published 9 years ago

dlinkedlist v1.6.4

Weekly downloads
1
License
MIT
Repository
github
Last release
9 years ago

#dlinkedlist

Simple Doubly Linked List implemented in Javascript (using Webpack). https://github.com/ArcQ/DoublyLinkedListJS

Install:

npm install dlinkedlist

##Iteration

#####Apply To Every Node To apply a callback function one very node, use list.applyToEveryNode() which takes 1-2 arguments:

  1. callback (required), (always returns true to apply to all nodes)
  2. arg: optional, if you need to plug arguments into callback
function MakeAllNodesZero(){
  var makeNodeZero = function(currentNode,arg){
    console.log(arg.test);
    currentNode.obj = 0;
  }
  var callbackArgument = {test};
  linkedListTest.applyToEveryNode(makeNodeZero,callbackArgument);
}

//iterate takes 4-5 arguments

#####Iterate With Stop Condition To iterate and apply your callback for a select number of nodes, use list.iterate() which takes 3-4 arguments

  1. callback (required), returns true if you want to continue (return true to apply to all nodes)
  2. isForward: true for forwards iteration(required) or false backwards iteration
  3. starting node
  4. ifCircular: true if you want tail's next to be head, head's prev to be tail
  5. arg: optional, if you need to plug arguments into callback
function Iterate(){   
    var i = 0;
    var iterateCallback = function(currentNode){
        currentNode.obj = i;
        i++;
        if(i<3){
            return true;
        }
        else{
            return false;
        }
    }
    var startingNode = linkedListTest.tail.prev;
    linkedListTest.iterate(iterateCallback,false,startingNode);
  }

##Basic Usage #####Create After importing DLinkedList.js

var list = window.dLinkedList();

#####Basic Node Structure

var node = {
		obj: obj,
		next: null,
		prev: null
	};

#####Push

var newNode = list.push(1);

#####FindFirst

//Set Search Condition Callback Based on CurrentNode Value

var searchCB = function(currentNode){
                return (currentNode.obj == "2");
            };
var oneNode = linkedListTest.findFirst(searchCB);

#####Insert

//insert 8 after 5
var searchCB = function(currentNode){
                return (currentNode.obj == "1");
            };
var oneNode = linkedListTest.findFirst(searchCB);
if (oneNode !== undefined)
{
    linkedListTest.insertAfter(oneNode,2);
    linkedListTest.insertBefore(oneNode,3);
}

####Remove

var searchCB = function(currentNode){
                return (currentNode.obj == "1");
            };
var oneNode = linkedListTest.findFirst(searchCB);
linkedListTest.remove(oneNode);

####Get Next (Circular Linked List) Use this function to retrive the next node if your linked list is linked in a circular manner.

var searchCB = function(currentNode){
                return (currentNode.obj == "1");
            };
var oneNode = linkedListTest.findFirst(searchCB);var twoNode = linkedListTest.cGetNext(oneNode);

####Get Prev (Circular Linked List) Use this function to retrive the previous node if your linked list is linked in a circular manner.

var searchCB = function(currentNode){
                return (currentNode.obj == "1");
            };
var oneNode = linkedListTest.findFirst(searchCB);var threeNode = linkedListTest.cGetPrev(oneNode);
1.6.4

9 years ago

1.6.3

9 years ago

1.6.2

9 years ago

1.7.1

9 years ago

1.7.0

9 years ago

1.5.0

9 years ago

1.4.0

9 years ago

1.3.4

9 years ago

1.3.3

9 years ago

1.3.2

10 years ago

1.3.1

10 years ago

1.3.0

10 years ago

1.2.6

10 years ago

1.2.5

10 years ago

1.2.4

10 years ago

1.2.3

10 years ago

1.2.2

10 years ago

1.2.1

10 years ago

1.2.0

10 years ago

1.1.0

10 years ago

1.0.3

10 years ago

1.0.2

10 years ago

1.0.1

10 years ago

1.0.0

10 years ago