You are viewing a single comment's thread. Return to all comments →
Solution using bubble sort
void swap(triangle *trA, triangle *trB) { triangle temp = *trA; *trA = *trB; *trB = temp; } float getArea(triangle tr) { float p = ((float)tr.a + (float)tr.b + (float)tr.c) / 2; return sqrt(p * (p - (float)tr.a) * (p - (float)tr.b) * (p - (float)tr.c)); } void sort_by_area(triangle* tr, int n) { for (int i = 0; i < n - 1; i++) for (int j = 0; j < n - i - 1; j++) if (getArea(*(tr + j)) > getArea(*(tr + j + 1))) swap(tr + j, tr + j + 1); }
Seems like cookies are disabled on this browser, please enable them to open this website
Small Triangles, Large Triangles
You are viewing a single comment's thread. Return to all comments →
Solution using bubble sort