title: Creating a second singly-linked list in reverse order of another list
body: <p>I need to create a function that takes a normal singly-linked list and creates another list in reverse order of the first list, the first element in the new list will be the last element in the original list and so on. </p>
  
  <p>My function for some reason only ever returns the same number over and over for the entirety of the new list. Therefore, if the last number in my original list is e.g. '50', the new list will be made up entirely of '50's. </p>
  
  <p>This is my code, what am I doing wrong? If anyone wants me to post the whole program for more clarity or context give me a shout.</p>
  
  <pre><code>void invert() {
      node *list1=top,*newlist,*temp,*prev;
      while (list1-&gt;next!=NULL) {
          list1=list1-&gt;next;
      }
      newlist=new node;
      newlist-&gt;num=list1-&gt;num;
      newlist-&gt;next=NULL;
      if (top2==NULL) {
          top2=newlist;
      }
      else {
          for (temp=top2;temp!=NULL;temp=temp-&gt;next) {
              prev=temp;
          }
          prev-&gt;next=newlist;
      }
      list1-&gt;next=NULL;
  }
  </code></pre>