From ASMBits

Consider the following struct:

struct ProfitList {
	unsigned int product_id;
	int profit;

An array of this struct can be used as a list of products (each with a product id) and the profit for selling each item.

Given an array of ProfitList, sort the list by profit (descending), then by product_id (ascending) if the profit is the same. In other words, the highest profit product should be moved to the beginning of the array, and if two products have the same profit, the one with smaller product id comes first.

void sort (struct ProfitList* profit_array, unsigned int profit_array_entries);

Expected solution length: Around 35 lines.

Sample Input

[See sample input below]

Sample Output

[The sorted array]

Write your solution here

Upload a source file...