Advertisement
Guest User

Untitled

a guest
Apr 9th, 2020
187
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.90 KB | None | 0 0
  1.  
  2. class circularList:public doublyLinkedList
  3. {
  4. private:
  5. public:
  6.     ///constructor
  7.     circularList():doublyLinkedList(){};
  8.     circularList(double_node* head, double_node* tail, int length):doublyLinkedList(head, tail, length)
  9.     {
  10.         tail->set_next(head);
  11.         head->set_prev(tail);
  12.     }
  13.     ///destructor
  14.     ~circularList()
  15.     {
  16.         double_node *current = head;
  17.  
  18.         while (current)
  19.         {
  20.             double_node* next = current->get_next();
  21.             delete current;
  22.             current = next;
  23.         }
  24.     }
  25.     ///copy constructor
  26.     circularList(circularList& lista):doublyLinkedList(lista)
  27.     {
  28.         tail->set_next(head);
  29.         head->set_prev(tail);
  30.     }
  31.     ///operator=
  32.     circularList operator=(circularList& lista)
  33.     {
  34.         double_node*  nod1 = lista.head;
  35.         double_node*  nod2 = head;
  36.         while(nod2 != lista.tail)
  37.         {
  38.             head = lista.head;
  39.             nod1 = (double_node*) nod1->get_next();
  40.             nod2 = (double_node*) nod2->get_next();
  41.         }
  42.         tail = lista.tail;
  43.         length = lista.length;
  44.         tail->set_next(head);
  45.         head->set_prev(tail);
  46.     }
  47.     ///cin si cout
  48.     void citire(istream &in);
  49.     void afisare(ostream &out);
  50.     friend istream& operator>>(istream&, circularList&);
  51.     friend ostream& operator<<(ostream&, circularList&);
  52. };
  53. void circularList::citire(istream& in)
  54. {
  55.     doublyLinkedList::citire(in);
  56.     tail->set_next(head);
  57.     head->set_prev(tail);
  58. }
  59. istream& operator>>(istream& in, circularList& lista)
  60. {
  61.     lista.citire(in);
  62.     return in;
  63. }
  64. void circularList::afisare(ostream& out)
  65. {
  66.   double_node *i = head->get_next();
  67.   while(i)
  68.     {
  69.       cout<<*i<<endl;
  70.       if(i == head)
  71.         break;
  72.       i = i->get_next();
  73.     }
  74. }
  75. ostream& operator<<(ostream& out, circularList& lista)
  76. {
  77.     lista.afisare(out);
  78.     return out;
  79. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement