Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Data Structure in C++ Doubly Linked Lists of ints http://staffwww.fullcoll.edu/aclifton/courses/cs133_fa16/files/dlist.h 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

image text in transcribed

image text in transcribed

http://staffwww.fullcoll.edu/aclifton/courses/cs133_fa16/files/dlist.h

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

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Design Application Development And Administration

Authors: Mannino Michael

5th Edition

0983332401, 978-0983332404

More Books

Students also viewed these Databases questions

Question

12-5 How will MIS help my career?

Answered: 1 week ago