-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathlinkedList.js
More file actions
37 lines (36 loc) · 776 Bytes
/
linkedList.js
File metadata and controls
37 lines (36 loc) · 776 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
class LinkedList{
constructor(data){
this.head = {
value : data,
next : null
}
this.tail = this.head;
}
addData(ele){
let newNode = {
value : ele,
next : null
}
this.tail.next = newNode;
this.tail=newNode;
}
listTraversing(){
let counter = 0;
let currentNode = this.head;
while(counter < this.head.length){
console.log(currentNode)
currentNode = currentNode.next
counter++;
}
}
}
const list = new LinkedList(300)
list.addData(400)
list.addData(400)
list.addData(400)
list.addData(400)
list.addData(400)
list.addData(400)
list.addData(400)
list.listTraversing()
console.log(list)