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
// 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
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
