Question: (In C++) Given the code for the implementation of a singly list with three data types: 1) Create a list in which the name of
(In C++) Given the code for the implementation of a singly list with three data types:


1) Create a list in which the name of the countries are in decreasing order (based on their population)
2) Create another list in which the country names are in lexicographical order (For example, the country Australia prints before Austria)
\#include using namespace std; // Node class class Node public: string country; string capital; int population: Node* next 3: // Singly linked list class class LinkedList public: Node* head; LinkedList() \{ head = NULL; \} // Add a new node at the front of the list void addNode(string country, string capital, int population) \{ Node newNode = new Node() newNode->country = country ; newNode->capital = capital newNode->population = population; newNode->next = head head = newNode \} // Remove the node at the front of the list void removeNode() if (head != NULL) {. Node* temp = head head = head->next; delete temp; 3 3 // Print the list void printList () . Node current = head while (current != NULL) cout country capital population next 3 // Divide the list into two parts for even and odd positions void divideList(LinkedList\& evenList, LinkedList\& oddList) \{ Node* current = head; int pos =1; while (current != NULL) if ( pos \% 2==0){ evenList.addNode (current->country, current->capital, current->population); else \{ oddList.addNode (current->country, current->capital, current->population); post+ current = current->next 3 3; int main(){ Linkedist countries string country, capital int population; // Add countries to the list while (true) cout "Enter a country name (or empty string to stop): "; getline (cin, country); if (country ==" ) break; 3 cout "Enter its capital: "; getline (cin, capital); cout population: cin.ignore(); countries.addNode(country, capital, population); \} // Print the original list cout
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
