C++!
Display numbers sorted based on the area!
Like that:(1,2)->(2,1)->(2,5)->(7,2)->(5,9)->(6,9)
#include <iostream>
using namespace std;
struct Rectangle
{
int height;
int width;
};
struct ListNode
{
Rectangle rect;
ListNode *next = nullptr;
int area;
ListNode(int h, int w)
{
rect.height = h;
rect.width = w;
area = rect.height * rect.width;
};
};
void display(ListNode* head)
{
/// TO DO: Add your code here
if(head == nullptr)
{
cout << “The list is empty.” << endl;
}
else if (head != nullptr && head->next == nullptr)
{
cout << “(” << head->rect.height << “, “<< head->rect.width << “)” << endl;
}
else
{
ListNode * Node = head;
while(Node != nullptr)
{
cout << “(” << Node->rect.height << “, “<< Node->rect.width << “)->”;
Node = Node->next;
}
cout << “@” << endl;
}
return;
}
/// Sort the list based on the size of the area