Skip to content

apurvapatel141092/array-to-linkedlist

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

array-to-linkedlist NPM version

Convert an array to Singly Linked List.

NPM

Install

Install with npm:

$ npm install array-to-linkedlist --save

Usage

Convert an array to Singly Linked List, access next node by .next and data by .data

var arrayToLinkedlist = require('array-to-linkedlist');

arrayToLinkedlist([1,2,3]);
//=>Node { data: 1, next: Node { data: 2, next: Node { data: 3, next: null } } }

Params

arrayToLinkedlist(array);
  • array: {Array} The Array to be converted into Singly Linked List.

Examples

var arrayToLinkedlist = require('array-to-linkedlist');

var array = [1,2,3];
var list = arrayToLinkedlist(array);

// Returns head of the linked list
console.log(list);

// Return data of the head node  
console.log(list.data));

// Return data of the next node  
console.log(list.next.data);

// Return all data

while(list){
console.log(list.data);
list = list.next;
}

Running tests

Install dev dependencies and run test:

$ npm install -d && npm test

Author

Apurva Patel

License

Copyright © 2016, Apurva Patel. Released under the MIT license.


About

Convert an array to Singly Linked List - npm package

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published