Here is my doubly linked list:

struct Num { int number; bool ring; Num *next, *prev; }; class List { protected : Num *head, *tail; public : List():head(NULL),tail(NULL){}; ~List(); int genNum(); void Add(int x); bool Remove(int i); }; 

Add item:

 void List::Add(int x) { Num *temp = new Num; temp->next = NULL; temp->number = x; if(head != NULL) { temp->prev = tail; tail->next = temp; tail= temp; } else { temp->prev = NULL; head = tail = temp; } } 

And deletion:

 bool List::Remove(int idx) { Num *current = head; Num *temp = NULL; int i = 0; while(current->next != NULL) { if(i != idx) { current = current->next; i++; } else { if (idx == 0) { temp = head; head = current; } else { temp = current->prev; current->prev = temp->prev; current->prev->next = current; } delete temp; return true; } } return false; } 

How to make a queue of it? (you can make the inheritance of the queue from the list)

  • implement only the functionality inherent in the queue. - AR Hovsepyan
  • @ARHovsepyan ah, thanks! - Digital Resistance

1 answer 1

 class List { protected : Num *head, *tail; public : List():head(NULL),tail(NULL){} ~List(); List(const List& t); List& operator =(const List& other); void push(const int&); void pop(); size_t size() const; bool operator <(const list& other) const; // если нужно bool empty() const { return !head; } Num& back() const { return *tail; } Num& front() const { return *head; } }; 

try to implement something like this