QuestionQuestion

Write a program in C++ using Microsoft Visual Studio 2010 that implements a function to insert an element into a doubly linked list so that after each insertion, elements on the list are in ascending order.
Implement two versions of the function, one for a class derived from DLL (stored in the "DLL.h" header file), as in

template<class T>
class MyDLL : public DLL<T> {
public:
void addInOrder(const T&);
};

and one for a class derived from the STL’s list class, as in

template<class T>
class MyDLLSTL : public list<T> {
public:
void addInOrder(const T&);
};

Solution PreviewSolution Preview

This material may consist of step-by-step explanations on how to solve a problem or examples of proper writing, including the use of citations, references, bibliographies, and formatting. This material is made available for the sole purpose of studying and learning - misuse is strictly forbidden.

#include <iostream>
#include "DLLNode.h"
#include "DLL.h"
#include "MyDLL.h"
#include "MyDLLSTL.h"
#include <list>
using namespace std;

template <typename T>
ostream& operator << (ostream& out, list<T> lst) {
for (list <T>::iterator i = lst.begin(); i != lst.end(); i++) // end() is one character out of the linked list
out << *i << ' ';
out << endl;
return out;
}

void testMyDLL()
{
MyDLL<int> dll;
cout << "inserting: " << dll;   //prints out the linked list
dll.addInOrder(10);
cout << "inserting: " << dll;
dll.addInOrder(20);
cout << "inserting: " << dll;
dll.addInOrder(30);
cout << "inserting: " << dll;
dll.addInOrder(15);
cout << "inserting: " << dll;
cout << "deleting from tail: " << dll.deleteFromTail() << endl;
cout<< dll;
cout << "deleting from tail: " << dll.deleteFromTail() << endl;
cout<< dll;
cout << "deleting from tail: " << dll.deleteFromTail() << endl;
cout<< dll;
cout << "deleting from tail: " << dll.deleteFromTail() << endl;
cout<< dll;
}

void testMyDLLSTL()
{
MyDLLSTL<int> dll;
cout << "inserting : " << dll;   //prints out the linked list
dll.addInOrder(10);
cout << "inserting : " << dll;
dll.addInOrder(20);
cout << "inserting : " << dll;
dll.addInOrder(30);
cout << "inserting : " << dll;
dll.addInOrder(15);
cout << "inserting : " << dll;
cout<< dll;
}

int main(int argc, char * argv[])
{
cout<<"MyDLL\n";
testMyDLL();
cout<<"MyDLLSTL\n";
testMyDLLSTL();
return 0;
}...
$20.00 for this solution

PayPal, G Pay, ApplePay, Amazon Pay, and all major credit cards accepted.

Find A Tutor

View available C-Family Programming Tutors

Get College Homework Help.

Are you sure you don't want to upload any files?

Fast tutor response requires as much info as possible.

Decision:
Upload a file
Continue without uploading

SUBMIT YOUR HOMEWORK
We couldn't find that subject.
Please select the best match from the list below.

We'll send you an email right away. If it's not in your inbox, check your spam folder.

  • 1
  • 2
  • 3
Live Chats