Subject Computer Science C-Family Programming

Question

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 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;
}...

This is only a preview of the solution. Please use the purchase button to see the entire solution

$20.00

or $1 if you
register a new account!

Assisting Tutor

Related Homework Solutions

Get help from a qualified tutor
Live Chats