Homework/HW03/ListNode.cc
ListNode *ListNode::copy() 
{
    ListNode *p, *temp, *tail=NULL, *head = NULL;

    // start from this node
    p = this; 
    while (p) 
    {
        // create a new node containing the same datum as p
        temp = new ListNode(p->datum);

        // if it's not the first, add it to the back of the new list
        if (head) 
        { 
            tail->next = temp; 
            tail = temp;
        }
        else // otherwise make it both first and last
            head = tail = temp;

        p = p->next; // move to the next node to copy
    }
    return head;
}
// copy the list starting with this node and following up to the end
copy the list starting with this node and following up to the end
copy the list starting with this node and following up to the end
ListNode *ListNode::copy() 
{
    ListNode *p, *temp, *tail=NULL, *head = NULL;
    p = this; 
    while (p) 
    {
        temp = new ListNode(p->datum);
        if (head) 
        { 
            tail->next = temp; 
            tail = temp;
        }
        else 
            head = tail = temp;
        p = p->next; 
    }
    return head;
}
ListNode * ListNode :: copy ( ) { ListNode * p , * temp , * tail = NULL , * head = NULL ; p = this ; while ( p ) { temp = new ListNode ( p -> datum ) ; if ( head ) { tail -> next = temp ; tail = temp ; } else head = tail = temp ; p = p -> next ; } return head ; }
copy the list starting with this node and following up to the end
copy the list starting with this node and following up to the end
// start from this node // create a new node containing the same datum as p // if it's not the first, add it to the back of the new list // otherwise make it both first and last // move to the next node to copy