Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class circularList:public doublyLinkedList
- {
- private:
- public:
- ///constructor
- circularList():doublyLinkedList(){};
- circularList(double_node* head, double_node* tail, int length):doublyLinkedList(head, tail, length)
- {
- tail->set_next(head);
- head->set_prev(tail);
- }
- ///destructor
- ~circularList()
- {
- double_node *current = head;
- while (current)
- {
- double_node* next = current->get_next();
- delete current;
- current = next;
- }
- }
- ///copy constructor
- circularList(circularList& lista):doublyLinkedList(lista)
- {
- tail->set_next(head);
- head->set_prev(tail);
- }
- ///operator=
- circularList operator=(circularList& lista)
- {
- double_node* nod1 = lista.head;
- double_node* nod2 = head;
- while(nod2 != lista.tail)
- {
- head = lista.head;
- nod1 = (double_node*) nod1->get_next();
- nod2 = (double_node*) nod2->get_next();
- }
- tail = lista.tail;
- length = lista.length;
- tail->set_next(head);
- head->set_prev(tail);
- }
- ///cin si cout
- void citire(istream &in);
- void afisare(ostream &out);
- friend istream& operator>>(istream&, circularList&);
- friend ostream& operator<<(ostream&, circularList&);
- };
- void circularList::citire(istream& in)
- {
- doublyLinkedList::citire(in);
- tail->set_next(head);
- head->set_prev(tail);
- }
- istream& operator>>(istream& in, circularList& lista)
- {
- lista.citire(in);
- return in;
- }
- void circularList::afisare(ostream& out)
- {
- double_node *i = head->get_next();
- while(i)
- {
- cout<<*i<<endl;
- if(i == head)
- break;
- i = i->get_next();
- }
- }
- ostream& operator<<(ostream& out, circularList& lista)
- {
- lista.afisare(out);
- return out;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement