Giter Site home page Giter Site logo

linked-list-module's Introduction

Linked List Module

Table of Contents

About

A linked list is a linear data structure where each element, called a node, is a separate object.

Linked list elements are not stored at contiguous location; the elements are linked using pointers.

  • Each node of a list is made up of two items - the data and a reference to the next node.
  • The last node has a reference to null.
  • The entry point into a linked list is called the head of the list.
  • It should be noted that head is not a separate node, but the reference to the first node. If the list is empty then the head is a null reference.

Getting Started

To be filled

Prerequisites

JavaScript enviornment

Installing

Install the Linked list module package from npm registry

npm i <repo>/Linked-List-Module

Require the module in the file where you want to use either using require or import syntax

const list = require('Linked-List-Module');
import list from 'Linked-List-Module';

Usage

Linked List Module helps you to include linked list in your JavaScript code. It is a single 0-indexed based list.

API Reference

Function Description
add(node [, index]) Adds new node to linked list
get(index) Get the element at given index
length Number of nodes in the list
print() Prints the list, for debugging
reverse() Reverses the list

add(node [, index])

The add(node [, index]) function adds the node to the linked List. There are two variations of adding a node in your linked list which this api provides that is adding the node at the end of the list or adding the node at any given position in your list. Keeping in mind the position specified should be a valid index.

Parameters

add accepts two parameters, second one is optional.

  1. Data to add - This is the data that you want to store as node and this api provide support for javascript data-type namely object, string, number, functions.
  2. Index - This specifies the index where you want to store the node in your linked List.If you do not provide this parameter then the node will always be inserted at the end of list. The index here should be a positive integer. Remember this is a 0 based linked list.
Usage

list.add({ 'a': 1 }) -- add to the end of list

list.add({ 'a': 1 }, 2) -- add the node from begining of list

list.add({ 'a': 1 }, 0) -- add to the beigining of the linked list i.e updates the head

get(index)

The get(index) function returns the node present at that index. If the index is not present it will return NULL.

Parameters

get accepts one parameter

  1. Index - This specifies the index for which you want to retrieve the node. The index should be apositive integer.
Usage

list.get(index)

length

The length property present for Linked List returns the current number of nodes of list.

Usage

list.length

print()

The print() method displays the nodes of the linked list. It takes no parameter

Usage

list.print()

reverse()

The reverse function reverse the linked list. It accepts no parameter.

Usage

list.reverse()

linked-list-module's People

Contributors

ankushdharkar avatar kratika0907 avatar

Watchers

James Cloos avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.