Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- template<typename T>
- const LinkedList <T> LinkedList<T>::operator-(const LinkedList & list) const
- {
- LinkedList<T> listA(*this);
- LinkedList<T> listB(list);
- int size1 = size(*this);
- int size2 = size(list);
- LinkedList<T> *newList = new LinkedList<T>();
- int minSize = (size1 < size2) ? size1 : size2;
- for (int i{}; i < minSize;i++)
- {
- newList->head = new Node();
- newList->head->data = listA.head->data - listB.head->data;
- cout << newList->head->data << endl;
- newList->head = newList->head->next;
- listA.head = listA.head->next;
- listB.head= listB.head->next;
- }
- while (listA.head != nullptr)
- {
- newList->head = new Node();
- newList->head->data = listA.head->data;
- cout << newList->head->data << endl;
- newList->head = newList->head->next;
- listA.head = listA.head->next;
- }
- while (listB.head != nullptr)
- {
- newList->head = new Node();
- newList->head->data= listB.head->data;
- cout << newList->head->data << endl;
- newList->head = newList->head->next;
- listB.head = listB.head->next;
- }
- return *newList;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement