We instantiate a char doubly linked list object Qaitlin and exercise all the agents of the object.
#include "simulation.h"
int main(void)
{
char input1[10] = {'1','2','3','4','5','11','7','8','9','a'};
char input2[6] = {'b','c','d','e','f','g'};
char c1 = 'u';
char c2 = 'w';
char c3 = 'x';
char c4 = 'y';
char c5 = 'z';
char *name[4] = {"charQaitlin","charQuinn","charJim","charPauli"};
cout << "Instantiating List Qaitlin" << endl;
CHAR_DLLIST Qaitlin(name[0]);
cout << endl << "Building Qaitlin List" << endl;
Qaitlin.build_list(input1,size1);
cout << "Qaitlin has " << Qaitlin.get_number_elements() << " elements";
cout << endl;
cout << endl << "Qaitlin = " << endl << Qaitlin << endl;
cout << endl << "Delete the element " << c1 << endl;
Qaitlin.delete_element(c1);
cout << endl << "Qaitlin = " << endl << Qaitlin << endl;
cout << endl << "Insert element " << c2 << "after "
<< c5 << endl;
Qaitlin.insert_after(c5,c2);
cout << endl << "Qaitlin = " << Qaitlin;
cout << endl << "Insert element " << c4 << "before "
<< c3 << endl;
Qaitlin.insert_before(c3,c4);
cout << endl << "Qaitlin = " << Qaitlin;
cout << "Qaitlin has " << Qaitlin.get_number_elements() << " elements";
cout << endl << "Sort the list Qaitlin." << endl;
Qaitlin.mergesort();
cout << endl << Qaitlin << endl;
cout << "Copy Constructor Test: Copy Qaitlin into Quinn:" << endl;
CHAR_DLLIST Quinn = Qaitlin;
cout << "Quinn = " << Quinn;
cout << "Instantiating List Quinn" << endl;
CHAR_DLLIST Jim(name[2]);
cout << endl << "Building Jim List" << endl;
Jim.build_list(input2,size2);
cout << "Jim has " << Jim.get_number_elements() << " elements";
cout << endl;
cout << endl << "Jim = " << endl << Quinn << endl;
cout << endl << "Overloaded Equal Test: Jim = Qaitlin" << endl;
Jim = Qaitlin;
cout << endl << "Jim = " << endl << Quinn << endl;
cout << "Test Overloaded Input Operator: " << endl;
CHAR_DLLIST Pauli(name[3]);
cin >> Pauli;
cout << "Pauli = " << Pauli;
return 0;
}
The corresponding output is:
Building Qaitlin List Qaitlin has 10 elements Qaitlin = 1<-->2<-->3<-->4<-->5<-->1<-->7<-->8<-->9<-->a. Delete the element u The element u is not in the list. u is not in the list; it can't be deleted. Qaitlin = 1<-->2<-->3<-->4<-->5<-->1<-->7<-->8<-->9<-->a. Insert element wafter z The element z is not in the list. z is not in the list, so do not insert. Qaitlin = 1<-->2<-->3<-->4<-->5<-->1<-->7<-->8<-->9<-->a. Insert element ybefore x The element x is not in the list. x is not in the list, so do not insert. Qaitlin = 1<-->2<-->3<-->4<-->5<-->1<-->7<-->8<-->9<-->a. Qaitlin has 10 elements Sort the list Qaitlin. 1<-->1<-->2<-->3<-->4<-->5<-->7<-->8<-->9<-->a. Copy Constructor Test: Copy Qaitlin into Quinn: Quinn = 1<-->1<-->2<-->3<-->4<-->5<-->7<-->8<-->9<-->a. Instantiating List Quinn Building Jim List Jim has 6 elements Jim = 1<-->1<-->2<-->3<-->4<-->5<-->7<-->8<-->9<-->a. Overloaded Equal Test: Jim = Qaitlin Jim = 1<-->1<-->2<-->3<-->4<-->5<-->7<-->8<-->9<-->a. Test Overloaded Input Operator: Please Enter the element which terminates input: ? Jim Peterson ? <===THIS IS WHAT WE ENTER AT THE KEYBOARD Pauli = J<-->i<-->m<-->P<-->e<-->t<-->e<-->r<-->s<-->o<-->n.