Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

(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:

image text in transcribed

image text in transcribed

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Systems A Practical Approach To Design Implementation And Management

Authors: THOMAS CONNOLLY

6th Edition

9353438918, 978-9353438913

More Books

Students also viewed these Databases questions

Question

5. Benchmark current training practices.

Answered: 1 week ago