Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C++ Double Linked list. I am having difficulties implementing the double linked list into the program DList.cpp #include using namespace std; class Item { public:

C++ Double Linked list. I am having difficulties implementing the double linked list into the programimage text in transcribedDList.cpp

#include

using namespace std;

class Item

{

public:

int val;

Item *next, *pre;

Item()

{

val =0;

next=0;

pre=0;

}

Item(int val)

{

this->val = val;

next=0;

pre=0;

}

};

class DLinkedList

{

int size;

Item *front;

Item *back;

public:

DLinkedList();

DLinkedList(const DLinkedList &list);

void push_back(Item *a);

void push_front(Item *a);

Item * pop_front();

Item * pop_back();

void insert(Item *a, int t); // insert the item a after the t-th element

void insertlist(DLinkedList *list, int t); // insert the whole list a after the t-th element

void display(ostream &out);

int getSize();

Item * getfront();

Item * getback();

void swap(Item *p, Item *q); //swap two items pointed by p and q, you can assume that p and q are something in the list

Item * extractmin(Item * start); // return the pointer of the min element after "start",

// here you can assume user will always input a valid pointer start that points to an item in the list

Item * extractmax(Item * start); // return the pointer of the max element after "start"

};

class myStack

{

DLinkedList list;

public:

myStack();

int getSize();

void in(Item *a);

Item *top();

void out();

};

class myQueue

{

DLinkedList list;

public:

myQueue();

int getSize();

void in(Item *a);

Item *front();

void out();

};

int main() {

return 0;

}

In this assignment, you are given several classes in the cpp file "DList.cpp". Your task is to complete the implementation of the classes specified as below. You need to submit a single cpp file that contains everything about your source code. It must be compilable and executable. Do not submit things irrelevant (such as .exe) etails are described below. 1 Your Taslk You are given a class "Item" that contains one integer value, and two pointers. You are going to build a doubly linked list class DLinkedList. I describe the tasks below Task 1: Implement the constructors (default and copy) of DLinkedList. You need to make sure that the copy constructor makes a separate copy of the list. Task 2: Implement push back, push front, pop back, pop front, get front, get back, display, swap. The functions are pretty self explanatory from their names Task 3: Implement Inserts. You should handle "insert an item" and "insert a list" Task 4: Implement extract min, extract max. They return the pointer to the min/max item in the list. If there is a tie, then choose arbitrarily among the mins/maxes. Task 5: Implement classes myQueue and myStack using DLinkedList. Do not re-write codes. (This task is pretty easy. There should not be any loops) Task 6: Design some tests to test your DLinkedList in the main function. You don't need to test your Stack nor Queue, as checking them is easy, assuming your DLinkedList is correct

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

The Structure Of The Relational Database Model

Authors: Jan Paredaens ,Paul De Bra ,Marc Gyssens ,Dirk Van Gucht

1st Edition

3642699588, 978-3642699580

More Books

Students also viewed these Databases questions