Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Here is what I have so far. Has to be C++ #include #include #include #include using namespace std; template class Node{ /ode class holds data

image text in transcribedimage text in transcribed

Here is what I have so far. Has to be C++

#include #include #include #include

using namespace std;

template

class Node{ /ode class holds data value and pointer public: Node (); Node (const Node& orig); Node* getNext(); Node* getprev(); bool hasNext(); bool hasPrev(); void setNext ( Node* newNext); void setPrev (Node* newPrev); int getVal(); void setVal(Node* value); private: Node* next; Node* prev; int value; };

template Node::Node(){ // node constructor next = NULL; } template Node::Node(const Node& orig){ Node = orig.getNext() val = orig.getVal() } template bool Node::hasNext(){ if (next != NULL) return true; else return false; } template bool Node::hasPrev(){ if (next == NULL) prev = orig.val; } template Node* Node::getNext(){ return next; } template Node* Node::getprev(){ return prev; } template Node* Node::getVal(){ return val; } template void Node* Node::setVal(int value){ val = value; } template void Node* Node::setNext(Node* newNext) { if (newNext = = NULL) next = NULL; else next = newNext -> next; } template void Node* Node::setVal(Node* newPrev){ prev = newPrev -> prev; }

template

class DLinkedList{

public: DLinkedList(); //Constructor head = new Node(0, NULL);

~DLinkedList(); //Destructor makeEmpty(); const DLinkedList& operator=(const DLinkedList&); // Assignment operator

Node* insert(const TYPE &, Node* ); // Node* isFirst(); //returns a reference to header node Node* next(Node* ) const; //reference to next node Node* precedent(Node* N); //reference to previous node Node* remove(Node* N); // removes the node to the right of N bool isEmpty () const; // returns true if list is empty void display (ostream & ); // write to a file the elements of the linked list Node* Min(Node* H); // finds the min value in a list headed by H void sort(); // sorts the list (selection sort)

};

DLinkedList::DLinkedList(){ }

template const DLinkedList& DLinkedList::operator=(const DLinkedList& Rhs){ if (this == &Rhs)return Rhs; makeEmpty(); if(Rhs.isEmpty()) return *this; Node *temp; temp=Rhs.head; do{ insertFirst(temp->value); temp=temp->next;

}while(temp!=NULL); return *this;

}

template Node* DLinkedList::insert(const TYPE & e, Node* current){ Node* temp= new Node(e, current -> next); current -> next = temp;

return temp;

}

DLinkedList::isFirst(){

}

DLinkedList::next(){

}

DLinkedList::precedent(Node* N){

}

template Node* DLinkedList::remove(Node* N){

Node* temp= N -> next; N -> next = N -> next -> next; delete temp; return N->next; }

template bool DLinkedList::isEmpty()const{ return (head->next==NULL); } }

void DLinkedList::display(){ return DLinkedList; }

DLinkedList::Min(Node * H){

}

void DLinkedList::sort(){

}

int main(){ DLinkedList theList; //initialize an empty list int size; //the size of list to be sorted int n; char filename[80]; cout > filename; ofstream out; out.open(filename); cout > size; srand(time(0)); Node *temp =theList.isFirst(); for (int i = 1; i n = rand() % 100; temp = theList.insert(n, temp); }

out

}

}

You are asked to write a program that implements a templated doubly linked list class DLinkedList including a recursive Selection Sort method. In addition to the appropri- ate constructor and destructor, the assignment operator, you should implement the follow- ing class methods (and any others if needed): Node TYPE> insert (const TYPE &, Node TYPE inserts a node Node Min (Node TYPE H) finds the min value in a list headed by H void sort //sorts the list (selection sort)

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 And Transaction Processing

Authors: Philip M. Lewis, Arthur Bernstein, Michael Kifer

1st Edition

0201708728, 978-0201708721

More Books

Students also viewed these Databases questions