Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C++ struct Country { std::string name; // name of the country std::string message; // message this country has received int numberMessages; // no. of messages

C++

image text in transcribedimage text in transcribed

struct Country { std::string name; // name of the country std::string message; // message this country has received int numberMessages; // no. of messages passed through this country Country *next; // pointer to the next country };

// class for storing and manipulating linked-list of countries class CountryNetwork { private: // pointer to head of linked-list of countries Country* head; public: // See writeup for method descriptions CountryNetwork(); bool isEmpty(); void insertCountry(Country* previous, std::string countryName); void deleteCountry(std::string countryName); void loadDefaultSetup(); Country* searchNetwork(std::string countryName); void deleteEntireNetwork(); void readjustNetwork(int start, int end); bool detectLoop(); Country* createLoop(std::string countryName); //void transmitMsg(std::string receiver, std::string msg); void printPath(); };

-->

bool CountryNetwork::detectLoop(){

}

Country* createLoop(sstring countryName){

}

bool detectLoop(); Traverse through the linked list (pointed to by head) to detect the presence of a loop. A loop is present in the list when the tail node points to some intermediate node (including itself) in the linked list, instead of pointing to null value. For example, the following list with "A" at the head has a loop: "A -> B- C -> D - E -> B". Notice that all the nodes are unique, except for node "B" which is repeated twice. This means that the last unique node E is connected back to the node B that appears before it in the linked list. Return true if the list contains a loop, else return false. Refer to the following links for the algorithm of loop detection: Country * createLoop(string countryName); As a way to test the detectLoop() function, develop a createLoop() function that adds a loop to the linked list pointed to by head. You'll achieve this by creating a link from the last node in the linked list to an intermediate node to loop back into. The function should return the last node of the linked list before creation of the loop. This will be needed by the driver function to break the loop. For example, consider the linked list: "A - B - C - D - E -> NULL". Suppose the function is called as - createLoop ("C"); After execution of the function the linked list should be "A - B - C - D -> E -> C" and it will return a pointer to the node E. NOTE: node E was the last node before creation of the loop. If the country is not present in the linked list, the function should return without creating a loop. A pointer to the last node should still be returned

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

Oracle 12c SQL

Authors: Joan Casteel

3rd edition

1305251032, 978-1305251038

More Books

Students also viewed these Databases questions

Question

=+what information would you need about the compact disc industry?

Answered: 1 week ago