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

Assisting Tutor

Related Homework Solutions

C++ Application For Biologists
Homework Solution
$40.00
Biology
Computer Science
Predators
Record
Species
Hierarchy
Lab Data
Animals
Registers
Memory
Variables
Loops
C++
Functions
C++ Problems
Homework Solution
$25.00
Programming
C++
Computer Science
Console Applications
Codes
Classifications
Students
Adults
Seniors
Subway
Customers
Fee Categories
Integers
Statements
Variables
Loops
Indexes
Average Values
Minimum
Maximum
Arrays
Functions
Input
Ou
Word Search Program in C
Homework Solution
$30.00
Programming
C
Computer Science
Word Search
Characters
Symbols
Strings
Text Files
Functions
Output
Input
Count Function
Loops
Statements
Pointers
Variables
Superhero Fight in C++
Homework Solution
$35.00
Programming
Classes
Vectors
Operators
Pointers
Computer Science
Superhero Fight
Game Developments
C++
OOP
Powers
Drivers
Lasers
Strength
Variables
Loops
Statements
Interfaces
Strings
Integers
Random Functions
Input
Output
Get help from a qualified tutor
Live Chats