Question: Data Structure in C++ Doubly Linked Lists of ints This is my code below: dlist.cc ------------------------------------------------------------------------------------------------------- #include #include dlist.h dlist::node* dlist::at(int n){ node* c =

Data Structure in C++

Doubly Linked Lists of ints

Data Structure in C++ Doubly Linked Lists of ints This is my

code below: dlist.cc ------------------------------------------------------------------------------------------------------- #include #include "dlist.h" dlist::node* dlist::at(int n){ node* c

This is my code below: dlist.cc

-------------------------------------------------------------------------------------------------------

#include #include "dlist.h"

dlist::node* dlist::at(int n){ node* c = _head; while(n > 0 && c){ c = c->next; n--; } return c; }

void dlist::insert(node* previous, int value){ node* n = new node{value, previous->next}; previous->next = n; }//update tail

void dlist::del(node* which){ node* nn = which->next; which->next = nn->next; delete nn; }

void dlist::push_back(int value){ node* n = new node{value, nullptr}; _tail->next = n; _tail-> n; }

void dlist::push_front(int value){ node* n = new node(value, nullptr); _head->prev = n; _head-> n;

}

void dlist::pop_front(){ node* n = _head; _head = _head->next; delete n; }

void dlist::pop_back(){ node* n = _tail; _tail = _tail->prev; delete n; }

int dlist::size() { node* c = _head; int s = 0; while(c){ s++; c = c->next; } return s; }

/ Returns true if the list is empty  bool empty(); private: node* _head = nullptr; node* _tail = nullptr; }; // **** Implement ALL the following functions ****  /* out  std::ostream& operator (std::ostream& out, dlist& l); /* a == b Compares two lists for equality, returning true if they have the same elements in the same positions. (Hint: it is *not* enough to just compare pointers! You have to compare the values stored in the nodes.) */ bool operator== (dlist& a, dlist& b); /* a + b Returns a new list consisting of all the elements of a, followed by all the elements of b (i.e., the list concatenation). */ dlist operator+ (dlist& a, dlist& b); /* reverse(l) Returns a new list that is the *reversal* of l; that is, a new list containing the same elements as l but in the reverse order. */ dlist reverse(dlist& l); 

--------------------------------------------------------------------------------

Please fix and complete my code, and I also need whole code contatining main function(list_tests.cc) for testing dlist.cc

--------------------------------------------------------------------------------

Output I need:

= _head; while(n > 0 && c){ c = c->next; n--; }

In this assignment, you will implement a doubly-linked list class. together with some list operations. To make things easier, you'll implement a list of int rather than a template class pragma once dlist. h Doubly linked lists of ints include Kostream class dlist public: d list struct node int value node next node prev; node' head() const return -head; node" tail() const t return -tail Implement ALL the following methods Returns the node at a particular index (0 is the head node at(int) Insert a new value, after an existing one void insert(node *previous int value Delete the given node void del (node which)

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 Databases Questions!