top button
Flag Notify
    Connect to us
      Facebook Login
      Site Registration Why to Join

Facebook Login
Site Registration
Print Preview

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

+1 vote
35 views
posted May 6 by anonymous

Share this question
Facebook Share Button Twitter Share Button Google+ Share Button LinkedIn Share Button Multiple Social 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:

Prerequisites:
- 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.
    else
    Exit.

  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 by Harshita

Useful Links with Similar Problem
Contact Us
+91 9880187415
sales@queryhome.net
support@queryhome.net
#280, 3rd floor, 5th Main
6th Sector, HSR Layout
Bangalore-560102
Karnataka INDIA.
QUERY HOME
...