/****************************************************** ** Name: ** Filename: LinksortDrv.cpp ** Project #: Data Structures And Other Objects Using C++ 2nd Edition (Micheal Main & Walter Savich) ** Project Description: Write a function that takes a linked list of integers and rearranges the nodes so that the integers are sorted into the order smallest to largest. Create a template that will allow this to be done with other types of data such as characters. ** Output: *Unsorted List Of Integers *Sorted List Of Integers *Unsorted List Of Characters *Sorted List Of Characters ** Input: None ** Algorithm: 1. Insert data into nodes of the first list 2. Find the node with the largest item in the first list. 3. Remove the largest node from first list 4. Insert this node at the head of the second list 5. Repeat steps 2-4 until all nodes are moved to second list. 6. Print sorted list. ******************************************************/ // Include files #include // used for cin, cout #include // used for getch() #include "Linksort.h" using namespace std; // Global Type Declarations // Function Prototypes void instruct (void); void pause (); void integer (); //Uses Data Type Int void character (); //Uses Data Type Char //Global Variables - should not be used without good reason. int main () { // Declaration section // Executable section instruct (); cout << "TESTING TEMPLATE WITH INTEGERS:\n\n"; integer (); cout << "\n\n\nTESTING TEMPLATE WITH CHARACTERS:\n\n"; character (); pause (); return 0; } void integer () //Using Data Type Int { // Declaration section node *Nodes[6]; int i; // Executable section for (i = 0;i < 6;i++) Nodes[i] = new node; for (i = 1;i < 6;i++) Nodes[i - 1] -> setLink(Nodes[i]); Nodes[5] -> setLink(NULL); //Data Nodes[0] -> setData(1000); Nodes[1] -> setData(543); Nodes[2] -> setData(700); Nodes[3] -> setData(12); Nodes[4] -> setData(340); Nodes[5] -> setData(11); cout << "The UnSorted List Of Integers: "; Nodes[0] -> printList(Nodes[0]); //Current List cout << "\n"; Nodes[0] -> sort_list(Nodes[0]); cout << "The Sorted List Of Integers: "; Nodes[0] -> printList(Nodes[0]); //Sorted List } void character () //Using Data Type Char { // Declaration section node *Nodes[6]; int i; // Executable section for (i = 0;i < 6;i++) Nodes[i] = new node; for (i = 1;i < 6;i++) Nodes[i - 1] -> setLink(Nodes[i]); Nodes[5] -> setLink(NULL); //Data Nodes[0] -> setData('b'); Nodes[1] -> setData('c'); Nodes[2] -> setData('f'); Nodes[3] -> setData('d'); Nodes[4] -> setData('e'); Nodes[5] -> setData('a'); cout << "The UnSorted List Of Characters: "; Nodes[0] -> printList(Nodes[0]); //Curent List cout << "\n"; Nodes[0] -> sort_list(Nodes[0]); cout << "The Sorted List Of Characters: "; Nodes[0] -> printList(Nodes[0]); //Sorted List } void instruct (void) { // Declaration section cout << "This is a test driver to test the sorting of a linked " << "list of integers and a\nlinked list of characters. " << "A template is used to allow the use of the two types " << "of data. \n" << "----------------------------------------------------" << "---------------------------" << endl; // Executable section } void pause () { // Declaration section // Executable section cout << "\nPress any key to continue..."; getch(); cout << "\r"; cout << " "; cout << "\r"; } /* Program Output This is a test driver to test the sorting of a linked list of integers and a linked list of characters. A template is used to allow the use of the two types of data. ------------------------------------------------------------------------------- TESTING TEMPLATE WITH INTEGERS: The UnSorted List Of Integers: 1000 543 700 12 340 11 The Sorted List Of Integers: 11 12 340 543 700 1000 TESTING TEMPLATE WITH CHARACTERS: The UnSorted List Of Characters: b c f d e a The Sorted List Of Characters: a b c d e f Press any key to continue... */