Question: Consider the following struct definitions, which represent a point on the Cartesian plan, and a rectangular region on the Cartesian plane, respectively. struct point {
Consider the following struct definitions, which represent a point on the Cartesian plan, and a rectangular region on the Cartesian plane, respectively. struct point { int x; /* x coordinate */ int y; /* y coordinate */ }; struct rectangle { struct point bottomLeft; struct point topRight; }; Write a function named "sort" that sorts an array of rectangles, smallest to largest. Two rectanges are ordered with each other according to the following rules (applied in this order):
The rectangle with the smaller area is less.
If the areas are the same, then the rectangle that begins further to the left is less.
If the areas are the same and the starting x-coordinates are equal, then the rectangle that begins at a lower point is less.
If the areas are the same, and the starting x- and y-coordinates are equal, then the shorter rectangle is less.
The function takes two arguments: an array of struct rectangle, and the size of the array (an integer). void sort(struct rectangle *array, int size); You may define additional functions in your solution.
Instructor Notes:
When it says
If the areas are the same, and the starting x- and y-coordinates are equal, then the shorter rectangle is less.
It means shorter in the y-axis, not length in the x-axis.
ALL THAT IS REQUIRED IS THE void sort(struct rectangle *array, int size); FUNCTION
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
