-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlinkedList.html
More file actions
71 lines (67 loc) · 1.75 KB
/
Copy pathlinkedList.html
File metadata and controls
71 lines (67 loc) · 1.75 KB
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
</head>
<body>
<h1>Linked List DSA</h1>
<script>
class Link {
constructor(data) {
this.head = {
value: data,
next: null,
};
this.tail = this.head;
this.length = 1;
}
appendData(nodeData) {
const newNode = {
value: nodeData,
next: null,
};
this.tail.next = newNode;
this.tail = newNode;
this.length++;
}
traversering() {
let counter = 0;
let currentNode = this.head;
while (counter < this.length) {
currentNode = currentNode.next;
console.log(currentNode, "traversing");
counter++;
}
}
deleteNode(index) {
let counter = 1;
let lead = this.head;
if (index === 1) {
this.head = this.head.next;
} else {
while (counter < index - 1) {
lead = lead.next;
counter++;
}
let nextNode = lead.next.next;
lead.next = nextNode;
console.warn(lead);
}
}
}
let newData = new Link(100);
newData.appendData(200);
newData.appendData(300);
// newData.appendData(400);
// newData.appendData(500);
// newData.appendData(600);
// newData.traversering();
// newData.deleteNode(3);
// console.log(newData, "NEW DATA");
console.log(newData, "NEW DATA");
// Traverserring the linked list
</script>
</body>
</html>