Question: Complete the C++ program for double link list. // version 0.1 #include using namespace std; struct node { node() {}; node(int val) :val(val) {}; int

Complete the C++ program for double link list. // version 0.1 #include using namespace std; struct node { node() {}; node(int val) :val(val) {}; int val; node* prev; node* next; }; class list { public: list() { head = new node; head->next = head; head->prev = head; } void display(); void push_front(const int& value); void push_back(const int& value); void pop_front(); void pop_back(); unsigned int size() const; bool empty() const; void clear(); private: node* head; }; int main() { list marc; cout marc.push_front(2); cout } unsigned int list::size() const { unsigned int _size(0); node* nptr; for (nptr = head->next; nptr != head; nptr = nptr->next) cout << nptr->val return _size; } void list::push_front(const int& value) { node* nptr; nptr = new node(value); nptr->next = head->next; head->next->prev = nptr; head->next = nptr; nptr->prev = head; } void list::push_back(const int& value) { node* nptr; nptr = new node(value); nptr->next = head->next; head->prev->next = nptr; head->prev = nptr; nptr->prev = head; } void list::pop_front() { node* nptr; if (head -> prev) { head = head->next; head->prev = NULL; } } void list::pop_back() { node* nptr; if (head->next) { head = head->prev; head->next = NULL; } } unsigned int _size(); { } bool empty() const; { } void list::clear(){ node* nptr; while ( head != NULL) { nptr = head; head = head->next; free(nptr); } cout } void display(); { }
Document Preview:

// version 0.1 #include using namespace std; struct node { node() {}; node(int val) :val(val) {}; int val; node* prev; node* next; }; class list { public: list() { head = new node; head->next = head; head->prev = head; } void display(); void push_front(const int& value); void push_back(const int& value); void pop_front(); void pop_back(); unsigned int size() const; bool empty() const; void clear(); private: node* head; }; int main() { list marc; cout next; nptr != head; nptr = nptr->next) cout val next = head->next; head->next->prev = nptr; head->next = nptr; nptr->prev = head; } void list::push_back(const int& value) { node* nptr; nptr = new node(value); nptr->next = head->next; head->prev->next = nptr; head->prev = nptr; nptr->prev = head; } void list::pop_front() { node* nptr; if (head -> prev) { head = head->next; head->prev = NULL; } } void list::pop_back() { node* nptr; if (head->next) { head = head->prev; head->next = NULL; } } unsigned int _size(); { } bool empty() const; { } void list::clear(){ node* nptr; while ( head != NULL) { nptr = head; head = head->next; free(nptr); } cout

Attachments:

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!