showing results for - "javascript singly linked list"
Giada
19 Jan 2019
1
2/**
3 * @constructor SLL
4 *
5 * @param head The head of the list.
6 * @param klass The reference to the SLLNode class
7 * @param size the size or length of the list.
8 * @arguments <klass:SLLNode>
9 * @description The SLL Factory
10 *
11 */
12export function SLL(klass = Node) {
13    this.head = new Node();
14    this.klass = Node;
15    this.size = 0;
16}
17
18/**
19 * @function Add|Method
20 *
21 * @returns SLLNode
22 * @param node The node you will append
23 * @arguments <key:string>
24 * @description A method that will insert a new node at the beginning of the
25 * list.
26 */
27SLL.prototype.add = function insert(key) {
28    const node = new this.klass(key);
29    this.head = this.head.add(node);
30    this.size++;
31    return this;
32}
33
34/**
35 * @function Find|Method
36 *
37 * @returns SLLNode
38 * @param key The key of the node you wish to find.
39 * @arguments <key:string>
40 * @description A method that will retireve a node associated with the
41 * corrosponding key.
42 */
43SLL.prototype.find = function find(key) {
44    return this.head && this.head.find(key);
45}
46
47/**
48 * @function Insert|Method
49 *
50 * @returns SLLNode
51 * @param key The key of the node you wish to append a new node.
52 * @param key1 The key of the node you wish to insert
53 * @arguments <key:string>, <key1:string>
54 * @description A method that will insert a new node into the middle of the
55 * list
56 */
57SLL.prototype.insert = function insert(key, key1) {
58    const node = new this.klass(key1);
59    return this.head && this.head.insert(key, node);
60}
61
62/**
63 * @function Del|Method
64 *
65 * @returns SLLNode
66 * @param key The key of the node you wish to delete.
67 * @arguments <key:string>
68 * @description A method that will delete a node associated with the
69 * corrosponding key.
70 */
71SLL.prototype.del = function del(key) {
72    return this.head.del(key);
73}
74
75/**
76 * @returns SLLNode
77 * @param key The key of the node you wish to create.
78 * @arguments <key:null?string>
79 * @description The SLLNode Interface
80 *
81 * @interface ISLLNode
82 */
83function ISSLNode(key=null) {
84    this.key = key;
85    this.next = null;
86}
87
88/**
89 * @constructor SLLNode
90 *
91 * @param key The key of the node you wish to create.
92 * @arguments <key:null?string>
93 * @description The SLLNode Factory
94 * 
95 * @implements ISLLNode
96 */
97export function SLLNode(key=null) {
98    ISSLNode.call(this, key=null);
99}
100
101/**
102 * @function Add|Method
103 *
104 * @returns SLLNode
105 * @param node The node you will append
106 * @arguments <node:SLLNode>
107 * @description A method that will insert a new node at the beginning of the
108 * list.
109 */
110SLLNode.prototype.add = function add(node) {
111    if(!this.key && !this.next) {
112        this.key = node.key;
113        this.next = node.next;
114        return node;
115    }
116    node.next = this;
117    return node;
118}
119
120/**
121 * @function Find|Method
122 *
123 * @returns SLLNode
124 * @param key The key of the node you wish to find.
125 * @arguments <key:string>
126 * @description A method that will retireve a node associated with the 
127 * corrosponding key.
128 */
129SLLNode.prototype.find = function find(key) {
130    if (this.key === key) {
131        this.next = null;
132        return this;
133    }
134    if (this.key !== key) {
135        if(!this.next) {
136            return 0;
137        }
138        return this.next.find(key);
139    }
140}
141
142/**
143 * @function Insert|Method
144 *
145 * @returns SLLNode
146 * @param key The key of the node you wish to append a new node.
147 * @param node The node you will append
148 * @arguments <key:string>, <node:SLLNode>
149 * @description A method that will insert a new node into the middle of the
150 * list
151 */
152SLLNode.prototype.insert = function insert(key, node) {
153    if (this.key === key) {
154        let tmp = this.next;
155        this.next = node;
156        node.next = tmp;
157        return node;
158    }
159    if (this.key !== key) {
160        if (!this.next) {
161            return 0;
162        }
163        return this.next.insert(key, node);
164    }
165}
166
167/**
168 * @function Del|Method
169 *
170 * @returns SLLNode
171 * @param key The key of the node you wish to delete.
172 * @param pre 
173 * @arguments <key:string>, <pre:null?SLLNode>
174 * @description A method that will delete a node associated with the
175 * corrosponding key.
176 */
177SLLNode.prototype.del = function del(key, pre=null) {
178    if (this.key === key) {
179       let tmp = this.next;
180       pre.next = tmp;
181        return this;
182    }
183    if (this.key !== key) {
184        if (!this.next) {
185            return 0;
186        }
187        return this.next.del(key, this);
188    }
189}
queries leading to this page
javascript linked list examplecreate a linked list javascriptlinked list using javascriptlinkedlist in jsjavascript singly linked list insertdatastructures linked list methods jsjs listnodesingly and doubly linked list in javascriptimplement linked list javascriptlinked list syntax in javascriptjavascript linked list code examplelinked list javascript implementationarray linked list javascriptmanipulate linked in with jscreate a new node in a linked list in jslinked list traversal javascriptjavascript implement linked listcreate singly linked list in javascripttraverse linked list javascriptsingly linked list jsjavascript how to implement a singly linked listhow to create singly linked list in jswhat is linked list in jscreating a link list using javascriptnode object linked list in j screate a linked list in javascriptpoint to single list node javascriptjs linkedlist class listnode javascriptjavascript lnikedlistlinked list add at head javascriptlinked lists in javascripthow to create a singly linked list jshow to insert an item at the end of a linked list javascriptreturn linked list javascripthow to traverse a linked list javascriptlinked list add method jshow to change linked list in jsjavascriip list linkgo through linked list javascriptjavascript built in linked listcreate linked list in javascriptnew list node javascriptjs linked list as classjavascript linked list add at indexsingly linked list javascriptlinked lists javascriptinsert linked list javascripthow to access element from singly linked list in javascriptnaming a linked list class javascriptsingly linked list in javascriptjavascript linkedlistcreate linked list javascriptare linked lists 0 indexed javascriptprint linked list javascripthow to write a linked list in javascirptjavascript linked list to check for an elementlistnode jslinked list javascript addtohead linker list jshow to use list node javascriptlinked list with jshow to parse linked list es7node js name origin come from linked listdemonstrate singly and doubly linked list in javascriptlink list javascriptclass node javascript linked listsingly linked list in javascriptnext linked list javascriptwhat is linked list head and tail in javascriptjs linkedlist insert at firstcreating a linked list using javascriptjavascript linked listlinked list implementation in javascriptlearn linked lists javascriptbest js linked listexamples of linked list in data structure javascripttype listnode jslinking nodes in javascriptconnect one linked list to another in javascriptwhen to use linked list in javascriptlinked list jshow to create a linked list in jsjs linked listjavscript linked listtraverse a linked list javascriptlinked list in javascriptsingly linked list in jsjavascript use object as linked listis prototype in javascript a linked listbuilt linkedlist object javascriptjavascript singly linked listhow to create a linkedlist in javascriptlistnode 28 29 javascriptcool examples of linked lists javascriptlinked list example interview js javascript linked listhow to add to the tail in jshow to implement a linked list in javascriptisngly linked list jsjs efficient linked listjavascript linked list 27sadd and remove element in linked list using javascriptwhere we use linked list in javascripthow to traverse to last node in linked list jslinked list in jslinked lists javascript appendingnodedefine linkedlist jsreturn linked list method javascriptcan linkedlists be used in for loop javascriptimplementing a linked list node class javascriptcheck for a value in linklist javascriptcreate a singly linked list jshow to make a node point to null in javascript linkedlisthow to work with linked list like structures in jqueryjavascript listnodedelete a node in linked list javascriptsingly and doubly linked list using jshow make linkedlist in jslinked list javascript find operationworking with linked list js examplewhat is a linked list javascriptsingly linked list js examplelistnode in jslinkedlist 27 object example jslistnode javascriptjavascript use linked listhow to code a linked list in javascripthow to check uif the type of the variabe is linked list in jsget head linked list javascriptdo people ever use linked lists in javascriptlinked list in javascript examplethis head javascriptjavascript practical use for linked listlinkedlist in javascriptnew listnode javascriptjavascript using linked listjavascript linked list show allgeneric linked list in javascripthow to implement a linked list javascriptimplement linked list in javascriptjavascript contains link list logicnode object linked list in js check for an element in linked list using javascriptjavascript linked linked listlinked list add head javascripthow to construct a linked list in javasciptnew listnode 28 29 jslist node javascriptimplement list in node jslinked list javascriptclass for creating a linked list in jsjs linked lists singly linkedhow to access data from linked list javascripthow to use linked list in javascriptlinked lists javascript insertatis a linked list in java script 0 indexedlinked list algorithm javascriptjs linked listslinked lists in jsnew listnode keyword javascriptinsert a node at the head of a linked list javascriptjavascript build singly linked listhow to singly link list in javascriptjs linked list examplelinked lists jshow to implement linked list in javascriptwhat are linked lists in javascriptlinked list in node jsjavascript singly linked list