Advertisement
Guest User

Untitled

a guest
Apr 9th, 2020
189
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.62 KB | None | 0 0
  1. class doublyLinkedList
  2. {
  3. protected:
  4.     double_node *head, *tail;
  5.     int length;
  6. public:
  7.     ///constructor
  8.     doublyLinkedList()
  9.     {
  10.         this->head = NULL;
  11.         this->tail = NULL;
  12.         this->length = 0;
  13.     }
  14.     doublyLinkedList(double_node *head, double_node* tail, int length)
  15.     {
  16.         this->head = new double_node;
  17.         this->tail = new double_node;
  18.         this->head = head;
  19.         this->tail = tail;
  20.         this->length = length;
  21.     }
  22.     ///destructor
  23.     ~doublyLinkedList()
  24.     {
  25.         double_node *current = head;
  26.         while ( current != tail ){
  27.             double_node* next =  current->get_next();
  28.             delete current;
  29.             current = next;
  30.         }
  31.         delete tail;
  32.     }
  33.  
  34.     ///operator=
  35.     doublyLinkedList operator=(doublyLinkedList& lista)
  36.     {
  37.         double_node*  nod1 = lista.head;
  38.         double_node*  nod2 = head;
  39.         cout<<"0";
  40.         ///tentativa mea
  41.         if(lista.head != NULL)
  42.         {
  43.             cout<<"1";
  44.             this->head = lista.head;
  45.             cout<<"2";
  46.             double_node*  nod1 = lista.head;
  47.             cout<<"3";
  48.             double_node*  nod2 = head;
  49.             cout<<"4";
  50.             while(nod2 != lista.tail)
  51.             {
  52.                 cout<<"5";
  53.                nod1 = (double_node*) nod1->get_next();
  54.                 cout<<"6";
  55.                 nod2 = (double_node*) nod2->get_next();
  56.                 cout<<"7";
  57.             }
  58.             tail = lista.tail;
  59.             length = lista.length;
  60.             this->length = lista.length;
  61.         }
  62.         return (*this);
  63.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement