Saturday 27 October 2012

Linked list Duplication

Given a linked list which has the node structure as shown below:

class Node{
  Node val; // note that the value also randomly points to some other node in the LL
  Node next;
}

How would you duplicate this linked list ?

Hint: I used an external hashmap DS in my solution.

Better solution:
http://www.geeksforgeeks.org/a-linked-list-with-next-and-arbit-pointer/

1 comment:

  1. Nice explanation with example. Thanks for sharing.

    Cheers,
    http://www.flowerbrackets.com/addition-operation-bitwise-operators-java/

    ReplyDelete