We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 57215ad commit 8ac2d0dCopy full SHA for 8ac2d0d
linked-list/partition.js
@@ -7,13 +7,18 @@ function partition(value) {
7
let left = null, right = null;
8
9
// partition list
10
- for(let current = this.head; current; current = current.next) {
11
- const copy = new Node(current.data);
+ let current = this.head;
+ while(current) {
12
+ const next = current.next;
13
+ current.next = null;
14
+
15
if(current.data < value) {
- left = append(left, copy);
16
+ left = append(left, current);
17
} else {
- right = append(right, copy);
18
+ right = append(right, current);
19
}
20
21
+ current = next;
22
23
24
// merge list
0 commit comments