diff --git a/04-dl-lists/StudentList.cpp b/04-dl-lists/StudentList.cpp index 820e1f7..094a493 100644 --- a/04-dl-lists/StudentList.cpp +++ b/04-dl-lists/StudentList.cpp @@ -83,10 +83,6 @@ bool StudentList::insertNode(Student dataIn) { ListNode *newNode; // A new node ListNode *pCur; // To traverse the list - // Allocate a new node and store num there. - newNode = new ListNode; - newNode->stu = dataIn; - // Initialize pointers pCur = head->forw; @@ -98,6 +94,10 @@ bool StudentList::insertNode(Student dataIn) { // Return false early if the name is a duplicate if (pCur->stu.name == dataIn.name) return false; + // Allocate a new node and store num there. + newNode = new ListNode; + newNode->stu = dataIn; + // Insert the new node between pPre and pCur ListNode *pPre = pCur->back; // The previous node pPre->forw = newNode;