Question
C++ struct Country { std::string name; // name of the country std::string message; // message this country has received int numberMessages; // no. of messages
C++
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(); };
void CountryNetwork:: readjustNetwork(int start_index, int end_index) { //TODO: Complete this function }
void readjustNetwork(int startIndex, int endindex); Manipulate next pointers to readjust the linked list. Here, startindex is index of a node from starting. Similarly endIndex is index of a node from beginning. The function will send the chunk of the link list between start index and end index at the end of the linked list. Consider the node at head as index 0. For example, if you have linked list like this: "A - B - C - D -> E-> NULL", and startindex=1 and endindex=3, then the linked list after readjustNetwork should be A -> E -> B - C -> D-> NULL". If you have linked list like this: "A - B - C - D -> NULL", and startindex=0 and endindex=2, then the linked list after readjustNetwork should be "D-> A -> B-> C -> NULL". Here, "D" is the new head. If the linked list is empty, print "Linked List is Empty". If endindex is bigger than the number of nodes in the linked list or smaller than 0, then print "Invalid end index". endindex should be lesser than the index of the last element in the linked list. Otherwise print "Invalid end index". If startIndex is bigger than the number of nodes in the linked list or smaller than 0, then print "Invalid start index". If startindex >endIndex print "Invalid indices". [NOTE: Change the order of the "node" (by manipulating the next pointers of each node), not the "value of the node"]Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started