title: Copying and then sorting a linked list
body: <p>I have a linked list of Nodes, each Node is defined as:</p>
  
  <pre><code>struct Node {
    char name[14];
    int counts[130];
    char gender;
    Node *nextPtr;
  };
  </code></pre>
  
  <p>I am copying this linked list with the following code:</p>
  
  <pre><code>// Create a copy of the current list
    Node *tempPtr;
    while (headPtr != NULL) {
      tempPtr = new Node;
      tempPtr = headPtr;
  
      // Advance the list
      headPtr = headPtr-&gt;nextPtr;
    } // End while loop
  </code></pre>
  
  <p>I need to copy the list so that I can sort it, I do not want to sort the original list. The sorting will be descending based on a value at a certain position of the counts[] array. I am wondering is somebody could tell me, am I copying the list correctly? And if I can have some insight as to how to go about and sort this list. I have written this in Java with no problem, I apologize for knowing too little of the c programming language. Any input will be greatly appreciated. Thank you. </p>
  
  <p>My apologies, I am to write this in the c++ programming language. However, I am not allowed to use C++ classes. I can only use C++ I/O stream, reference parameters, and dynamic memory allocation.</p>
  
  <p>My main goal here is to make a list of pointers to the existing nodes, and then sort it without copying the nodes or disturbing the original list.</p>