title: C program to make a second copy of a linked list
body: <p>I was writing a C code to copy the contents of a Linked List onto another list. I want to know if there is a more efficient way of doing this.</p>
  
  <p>Which is better?</p>
  
  <pre><code>struct node *copy(struct node *start1)
  {
  struct node *start2=NULL,*previous=NULL;
  
  while(start1!=NULL)
  {
      struct node * temp = (struct node *) malloc (sizeof(struct node));
      temp-&gt;info=start1-&gt;info;
      temp-&gt;link=NULL;
  
      if(start2==NULL)
      {
          start2=temp;
          previous=temp;
      }
      else
      {
          previous-&gt;link=temp;
          previous=temp;          
      }
      start1=start1-&gt;link;
  }
  return start2;
  }
  </code></pre>
  
  <p>OR</p>
  
  <pre><code>struct node *copy(struct node *start1)
  {
      if(start1==NULL) return;
      struct node *temp=(struct node *) malloc(sizeof(struct node));
      temp-&gt;info=start1-&gt;info;
      temp-&gt;link=copy(start1-&gt;link);
      return temp;
  }
  </code></pre>