Advertisement
Guest User

Untitled

a guest
Feb 21st, 2020
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.77 KB | None | 0 0
  1. MyList(const MyList& otherList)
  2. {
  3. if ( otherList.head == nullptr)
  4. head = tail = nullptr; // if "otherList" is empty the new list is empty too.
  5. else
  6. {
  7. head = new MyNode<T>( otherList.head ); // allocate head and copy data
  8. MyNode<T> tempOther* = otherList.head->next;
  9. MyNode<T> temp* = head;
  10. while (tempOther != nullptr )
  11. {
  12. temp->next = new MyNode<T>( tempOther, nullptr, temp ); // allocate next elemnt and copy data ( predecessor is "temp" )
  13. temp = temp->next; // temp refers to last element of list
  14. tempOther = tempOther->next; // step one forward
  15. }
  16. tail = temp;
  17. }
  18. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement