top button
Flag Notify
    Connect to us
      Facebook Login
      Site Registration

Facebook Login
Site Registration

How to clone each node of given linked list using C?

+1 vote
How to clone each node of given linked list using C?
posted May 6, 2017 by anonymous

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

0 votes

Cloning of a linked list means create a linked list from an existing linked which would have same node values in the same order.
I would like to share the algorithm as following:

- Source linked list pointer
- Head node pointer for clone list
- Last pointer, pointing to head node. This pointer points to the last node after insertion of new node.

  1. Iterate through existing list for each node
    if node next is not null then
    Execute step 2.

  2. Allocate a node, assign the value to node from source node and insert this new node to target list just after the last node.
    Move the last pointer to this new node of target list.

answer May 6, 2017 by Harshita
Contact Us
+91 9880187415
#280, 3rd floor, 5th Main
6th Sector, HSR Layout
Karnataka INDIA.