Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Doubly linked list I have a question when it comes to the copy constructor in a

ID: 642438 • Letter: D

Question

Doubly linked list

I have a question when it comes to the copy constructor in a doubly linked list how exactly can you implement that I understand how the doubly linked list I just don't understand as to how to make a copy of the list

If you can give a code example would be helpful

Explanation / Answer

// copy constructor DoublyLinkedList::DoublyLinkedList(const DoublyLinkedList& dll) { // Initialize the list header = 0; trailer = 0; header.next = &trailer; trailer.prev = &header; // Copy from dll DListNode* head = new DListNode; head->prev = dll.header.prev; head->obj = dll.header.obj; head->next = dll.header.next; DListNode* tail = new DListNode; tail->prev = dll.trailer.prev; tail->obj = dll.trailer.obj; tail->next = dll.trailer.next; DListNode* curr = new DListNode; curr->prev = head; while(curr != tail) { DListNode* n = new DListNode; curr->next = n; n = curr->prev->next; curr = curr->next; } curr = tail; }

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote