Title Description
Enter a complex list with node values in each node, and two pointers, one pointing to the next node, and the other a special pointer to any node.
Code:
<span style= "color: #000099;" >import java.util.hashmap;import java.util.iterator;import Java.util.map.entry;import Java.util.Set;public class Solution {public Randomlistnode Clone (Randomlistnode phead) {hashmap<randomlistnode,randomlistnode> m AP = new Hashmap<randomlistnode,randomlistnode> (); Randomlistnode p = phead; Randomlistnode q = New Randomlistnode (-1); while (p!=null) {Randomlistnode t = new Randomlistnode (P.label); Map.put (P, t); p = p.next; Q.next = t; Q = t; } set<entry<randomlistnode,randomlistnode>> Set = Map.entryset (); Iterator<entry<randomlistnode,randomlistnode>> it = Set.iterator (); while (It.hasnext ()) {Entry<randomlistnode, randomlistnode> next = It.next (); Next.getvalue (). Random = Map.get (Next.getkey (). Random); } return Map.get (Phead); }}</span>
Copy of the complex linked list of the offer (48) of the Sword