array-to-linkedlist

0.1.1 • Public • Published

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.


Package Sidebar

Install

npm i array-to-linkedlist

Weekly Downloads

4

Version

0.1.1

License

MIT

Last publish

Collaborators

  • apurvapatel