-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.js
48 lines (40 loc) · 802 Bytes
/
test.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
44
45
46
47
48
let list =
{
value: 1,
next: {
value: 2,
next: {
value: 3,
next: {
value: 4,
next: {
value: 5,
next: null
}
}
}
}
}
let dummyList = {
next: list
};
let head = dummyList;
let left = 2;
for (let i = 1; i < left; i++) {
head = head.next;
}
// console.log(JSON.stringify(head));
let right = 4;
let curr = head.next;
// console.log(curr);
let next = null;
let prev = null;
for (let i = left; i < right; i++) {
next = curr.next;
curr.next = next.next;
next.next = head.next;
head.next = next;
}
console.log(JSON.stringify(dummyList.next));
// console.log(JSON.stringify(prev));
// console.log(JSON.stringify(list));