Question: You need to implement the merge - sort algorithm to sort a list of cities, but the sorting should only consider the population of the
You need to implement the mergesort algorithm to sort a list of cities, but the sorting should only consider the population of the cities. No other criteria should be used in the sorting process. However, if two cities have the same population, they should maintain their original order as in the input. This is commonly referred to as a stable sort An Onlogntime algorithm is sufficient to pass any feasible test cases.
Input You need to read the input from the console. The input consists of n lines of data. Each line i contains two positive integers: ai which is the index of the city, and pi representing the population of the city. You can assume that ai and pi
Output You need to output to console. The output from line to line n you need to output the cities in ascending order of population.
Example: Below are examples of input and output:
Example input: Example output:
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
