Advertisement
Guest User

Untitled

a guest
Feb 26th, 2020
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.32 KB | None | 0 0
  1. #include<iostream>
  2. using namespace std;
  3.  
  4. class Album {
  5.  
  6.     struct Node
  7.     {
  8.         int a;
  9.         Node *next;
  10.     };
  11.  
  12.     Node *head = nullptr;
  13.  
  14. public:
  15.  
  16.     int size = 0;
  17.  
  18.     friend void operator +=(Album& obj1, int element)
  19.     {
  20.         Node *current = new Node;
  21.         current->a = element;
  22.         current->next = obj1.head;
  23.         obj1.head = current;
  24.         obj1.size++;
  25.  
  26.     }
  27.  
  28.     friend ostream& operator << (ostream &out, Album obj1)
  29.     {
  30.         while (obj1.head != NULL)
  31.         {
  32.             cout << obj1.head->a << endl;
  33.             obj1.head = obj1.head->next;
  34.         }
  35.         cout << "Количество эллементов - " << obj1.size << endl;
  36.         return out;
  37.     }
  38.  
  39.    
  40.     friend bool operator ==(Album obj1,Album obj2)
  41.     {
  42.         if (obj1.size !=  obj2.size)
  43.             return false;
  44.         while (obj1.head !=NULL)
  45.         {
  46.             if (obj1.head->a != obj2.head->a)
  47.                 return false;
  48.             obj1.head = obj1.head->next;
  49.             obj2.head = obj2.head->next;
  50.         }
  51.         return true;
  52.     }
  53.  
  54.     Album sort(Album obj1)
  55.     {
  56.    
  57.    
  58.     }
  59.  
  60. };
  61.  
  62. int main()
  63. {
  64.     setlocale(LC_ALL, "ru");
  65.     Album obj1;
  66.     Album obj2;
  67.     int c;
  68.     cin >> c;
  69.     for (int i = 0; i < c; i++)
  70.     {
  71.         obj1 += rand();
  72.         obj2 += rand() % 22;
  73.     }
  74.     cout << obj1;
  75.     cout << endl;
  76.     cout << obj2;
  77.     if (obj1 == obj2)
  78.         cout << "списки равны" << endl;
  79.     else
  80.     {
  81.         cout << "списки неравны" << endl;
  82.     }
  83.  
  84.  
  85.     system("pause");
  86.     return 0;
  87.  
  88. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement