Skip to content

Commit 62f19bd

Browse files
authored
Create LinkedList.js
1 parent 3be6003 commit 62f19bd

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

03-DataStructures/LinkedList.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
class Node {
2+
constructor(value) {
3+
this.value = value;
4+
this.next = null;
5+
}
6+
}
7+
8+
class LinkedList {
9+
constructor() {
10+
this.head = null;
11+
this.tail = null;
12+
this.length = 0;
13+
}
14+
15+
append(value) {
16+
const newNode = new Node(value);
17+
if (!this.head) {
18+
this.head = newNode;
19+
this.tail = newNode;
20+
} else {
21+
this.tail.next = newNode;
22+
this.tail = newNode;
23+
}
24+
this.length++;
25+
}
26+
}
27+
28+
const list = new LinkedList();
29+
list.append(1);
30+
list.append(2);
31+
list.append(3);
32+

0 commit comments

Comments
 (0)