Question: NEED C++ CODE PLEASE You have been provided with a linked list of several nodes, each containing two types of data: a name of type

NEED C++ CODE PLEASE

You have been provided with a linked list of several nodes, each containing two types of data: a name of type string, and a grade of type double.

First, display the list to the user as is (this is already finished for you). Then, using any method of your choice (push onto stacks, put into vectors or arrays and sort via bubble, binary, etc.) EXCEPT explicitly reordering the linked list itself (i.e. change the order in which the nodes point; that would be too easy!), reorder and display the linked list (display both name and grade) to the user in:

Alphabetical order, by name

Descending order (highest to lowest), by grade

Using Starter code:

#include #include using namespace std; class nodeType { public: string name; double grade; nodeType *link; nodeType() // Default constructor. Utilized below to skip printing anything for head node. { name = ""; grade = 0; } }; int main() { // (Declared linked list nodes) nodeType *head, *name1, *name2, *name3, *name4, *current; head = new nodeType; name1 = new nodeType; name2 = new nodeType; name3 = new nodeType; name4 = new nodeType; // Node initializations head -> link = name1; // 'head' (first, or initial pointer in the linked list) points to the location of name1 // Notice that we did not initialize name or grade for it like the others in the list below, // hence, (by default) it will get the default constructor data name1 -> name = "John"; name1 -> grade = 98; name1 -> link = name2; name2 -> name = "Sarah"; name2 -> grade = 99; name2 -> link = name3; name3 -> name = "Amir"; name3 -> grade = 96; name3 -> link = name4; name4 -> name = "Ingrid"; name4 -> grade = 100; name4 -> link = nullptr; // Final node in linked list is assigned the null pointer current = head; // Temporary pointer that traverses the linked list // (Sequentially, as connected above) while (current != nullptr) // Traverse the linked list and print the name stored at each node. { if (current -> name != "" && current -> grade != 0) // Checks if node has does not have default data (only the head node does); This will avoid printing anything for the head node { cout << current->name << endl; cout << current->grade << endl << endl; } current = current -> link; // Redirect 'current' pointer to next address in linked list } }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!