Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- MyList(const MyList& otherList)
- {
- if ( otherList.head == nullptr)
- head = tail = nullptr; // if "otherList" is empty the new list is empty too.
- else
- {
- head = new MyNode<T>( otherList.head ); // allocate head and copy data
- MyNode<T> tempOther* = otherList.head->next;
- MyNode<T> temp* = head;
- while (tempOther != nullptr )
- {
- temp->next = new MyNode<T>( tempOther, nullptr, temp ); // allocate next elemnt and copy data ( predecessor is "temp" )
- temp = temp->next; // temp refers to last element of list
- tempOther = tempOther->next; // step one forward
- }
- tail = temp;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement