title: Copy the reverse of a linked list
body: <h3>copyRev</h3>
  <pre><code>void copyRev(node *head1, node *&amp;head2)
  {
  
      stack&lt;int&gt; dat;
      node* curr = head1;
      while(curr!=NULL){
          dat.push(curr-&gt;data);
          curr = curr-&gt;next;
      }
      while(!dat.empty()){
          append(head2,dat.top());
          dat.pop();
      }
  
  }
  </code></pre>
  <h3>append</h3>
  <pre><code>void append(node* &amp;head, int data){
  
      if(head==NULL){
          head= new node;
          head-&gt;data = data;
          head-&gt;next = NULL;
      }
      else{
  
          node *curr = head;
          while((curr)-&gt;next!=NULL){
              (curr) = (curr)-&gt;next;
          }
          (curr)-&gt;next = new node;
          (curr) = (curr)-&gt;next;
          (curr)-&gt;data = data;
          (curr)-&gt;next = NULL;
      }
  }
  </code></pre>
  <p>Well, I'm trying to clone the reverse of a linked list. I know how to reverse a list in place. But this code gives me a <code>Bus error(code dumped)</code>.</p>
  <p>This is how I call the function in <code>main()</code></p>
  <pre><code>node *head;
  
      for(int i = 0;i&lt;9;i++){
          append(head,i*i);
      }
      node *revHead;
      printList(head);
  
      copyRev(head,revHead);
      printList(revHead);
  </code></pre>
  <p>in <code>append()</code> function, I check for <code>NULL</code> head and create a new node if it is NULL. moreover, the append function properly adds the elements to the list. The problem arose only after I called the <code>copyRev</code> procedure.</p>
  <p>I have tried in-place reversing and it works. I need to clone the reverse of a linked list. Both Iterative and Recursive solutions are welcome. Also please point out the error in the above code.</p>
  <p>This is my own practice problem but not a homework problem</p>