Advertisement
Guest User

Untitled

a guest
Sep 21st, 2018
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.05 KB | None | 0 0
  1. template<typename T>
  2. const LinkedList <T> LinkedList<T>::operator-(const LinkedList & list) const
  3. {
  4.     LinkedList<T> listA(*this);
  5.     LinkedList<T> listB(list);
  6.     int size1 = size(*this);
  7.     int size2 = size(list);
  8.     LinkedList<T> *newList = new LinkedList<T>();
  9.     int minSize = (size1 < size2) ? size1 : size2;
  10.  
  11.     for (int i{}; i < minSize;i++)
  12.     {
  13.         newList->head = new Node();
  14.         newList->head->data = listA.head->data - listB.head->data;
  15.         cout << newList->head->data << endl;
  16.         newList->head = newList->head->next;
  17.         listA.head = listA.head->next;
  18.         listB.head= listB.head->next;
  19.     }
  20.     while (listA.head != nullptr)
  21.     {
  22.         newList->head = new Node();
  23.         newList->head->data = listA.head->data;
  24.         cout << newList->head->data << endl;
  25.         newList->head = newList->head->next;
  26.         listA.head = listA.head->next;
  27.     }
  28.     while (listB.head != nullptr)
  29.     {
  30.         newList->head = new Node();
  31.         newList->head->data= listB.head->data;
  32.         cout << newList->head->data << endl;
  33.         newList->head = newList->head->next;
  34.         listB.head = listB.head->next;
  35.     }
  36.     return *newList;
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement