-
Notifications
You must be signed in to change notification settings - Fork 1.8k
/
Exercise_3.js
43 lines (43 loc) · 965 Bytes
/
Exercise_3.js
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
class LinkedList {
constructor() {
this.head = null; // head of linked list
}
/* Linked list node */
static Node = class {
constructor(d) {
//Constructor here
this.data = d;
this.next = null;
}
}
/* Function to print middle of linked list */
//Complete this function
function printMiddle() {
//Write your code here
//Implement using Fast and slow pointers
}
function push(new_data) {
let new_node = new this.Node(new_data);
new_node.next = this.head;
this.head = new_node;
}
function printList() {
let tnode = this.head;
while (tnode != null) {
console.log(tnode.data + "->");
tnode = tnode.next;
}
console.log("NULL");
}
}
let llist = new LinkedList();
for (let i = 15; i > 0; --i) {
llist.push(i);
llist.printList();
llist.printMiddle();
}