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.89 KB | None | 0 0
  1. //checks if two lists are equal in state (contain the same values in the same order)
  2. bool LinkedList::operator ==(const LinkedList& other) const
  3. {
  4. //Test if the two lists are equal
  5. return (other.head && this->head) && (other.tail && this->tail);
  6. }
  7.  
  8. //checks if two lists are not equal in state
  9. bool LinkedList::operator !=(const LinkedList& other) const
  10. {
  11. //flag is initialised to 1
  12. int flag = 1;
  13. //temp2 is set to head node and temp2 is set to the other head node
  14. Node *temp1 = head;
  15. Node *temp2 = other.head;
  16. while (temp1 != nullptr && temp2 != nullptr) {
  17. if (temp1->data != temp2->data) flag = 0;
  18. //temp1 and temp2 is both set to the next node
  19. temp1 = temp1->next; temp2 = temp2->next;
  20. }
  21. if (temp1 == nullptr || temp2 == nullptr && !(temp1 == nullptr&&temp2 == nullptr))
  22. //flag is set to 0
  23. flag = 0;
  24.  
  25. if (flag == 1)
  26. {
  27. return false;
  28. }
  29.  
  30. return true;
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement