Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //checks if two lists are equal in state (contain the same values in the same order)
- bool LinkedList::operator ==(const LinkedList& other) const
- {
- //Test if the two lists are equal
- return (other.head && this->head) && (other.tail && this->tail);
- }
- //checks if two lists are not equal in state
- bool LinkedList::operator !=(const LinkedList& other) const
- {
- //flag is initialised to 1
- int flag = 1;
- //temp2 is set to head node and temp2 is set to the other head node
- Node *temp1 = head;
- Node *temp2 = other.head;
- while (temp1 != nullptr && temp2 != nullptr) {
- if (temp1->data != temp2->data) flag = 0;
- //temp1 and temp2 is both set to the next node
- temp1 = temp1->next; temp2 = temp2->next;
- }
- if (temp1 == nullptr || temp2 == nullptr && !(temp1 == nullptr&&temp2 == nullptr))
- //flag is set to 0
- flag = 0;
- if (flag == 1)
- {
- return false;
- }
- return true;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement