When this function runs, it overwrites the first node in the list. I can't for the damn of me, figure out. Any help? Please give an explanation too, trying to learn, not turn in homework lol. K thanks.
Code:// ============= // InsertFirst() // ========================================== void DoublyLinkedList::InsertFirst( int value ){ Node* newNode = new Node(value, NULL, NULL); Node* ptr; /* ptr = first; first = newNode; newNode->previous = first; newNode->next = ptr; */ newNode->next = first; first = newNode; newNode->previous = first; if(Length() > 1){ newNode->next->previous = newNode; } else newNode->next = NULL; if(last == NULL) last = first; }//InsertFirst() // ================



1Likes
LinkBack URL
About LinkBacks
.




