-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCloneDLL.java
More file actions
30 lines (26 loc) · 842 Bytes
/
Copy pathCloneDLL.java
File metadata and controls
30 lines (26 loc) · 842 Bytes
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
package Recursion.Extras;
import java.util.*;
class NodeDLL {
int data;
NodeDLL next, random;
NodeDLL(int data) {
this.data = data;
next = random = null;
}
}
public class CloneDLL {
static void clone(NodeDLL head) {
HashMap<NodeDLL, NodeDLL> map = new HashMap<>();
for(NodeDLL current = head; current != null; current = current.next) {
map.put(current, new NodeDLL(current.data));
}
for(NodeDLL current = head; current != null; current = current.next) {
NodeDLL cloneCurrent = map.get(current);
cloneCurrent.next = map.get(current.next);
cloneCurrent.random = map.get(current.random);
}
NodeDLL head_2 = map.get(head);
}
public static void main(String[] args) {
}
}