Advertisement
Guest User

Untitled

a guest
Mar 30th, 2017
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.68 KB | None | 0 0
  1. //appends the deep copies of the nodes of rhs on to the end of this list
  2. void LinkedList::appendList(const LinkedList& rhs)
  3. {
  4. //Allocate new memory for a new node
  5. Node *tempNode;
  6. //The node is set to rhs head
  7. tempNode = rhs.head;
  8. //current node is set to tail by default
  9. Node *currentNode = tail;
  10. while (tempNode != nullptr)
  11. {
  12. //Allocate new memory for a new node
  13. Node *temp2 = new Node;
  14. //Copy over the value
  15. temp2->data = tempNode->data;
  16. //set the next node to the temp2 node
  17. currentNode->next = temp2;
  18. //set current node to the next node
  19. currentNode = currentNode->next;
  20. //set the temporary node to the next node
  21. tempNode = tempNode->next;
  22. }
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement