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

These solutions may offer step-by-step problem-solving explanations or good writing examples that include modern styles of formatting and construction of bibliographies out of text citations and references. Students may use these solutions for personal skill-building and practice. Unethical use 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;
}...

By purchasing this solution you'll be able to access the following files:
Solution.zip.

$18.00
for this solution

or FREE if you
register a new account!

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