You are viewing a single comment's thread. Return to all comments →
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++) { double p1 = (double)(tr[j].a + tr[j].b + tr[j].c) / 2.0; double s1 = sqrt(p1 * (p1 - (double)tr[j].a)(p1 - (double)tr[j].b)(p1 - (double)tr[j].c)); double p2 = (double)(tr[j+1].a + tr[j+1].b + tr[j+1].c) / 2.0; double s2 = sqrt(p2 * (p2 - (double)tr[j+1].a)(p2 - (double)tr[j+1].b)(p2 - (double)tr[j+1].c)); if (s1 > s2) { triangle temp; temp = tr[j]; tr[j] = tr[j+1]; tr[j+1] = temp; } } } }
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 →
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++) { double p1 = (double)(tr[j].a + tr[j].b + tr[j].c) / 2.0; double s1 = sqrt(p1 * (p1 - (double)tr[j].a)(p1 - (double)tr[j].b)(p1 - (double)tr[j].c)); double p2 = (double)(tr[j+1].a + tr[j+1].b + tr[j+1].c) / 2.0; double s2 = sqrt(p2 * (p2 - (double)tr[j+1].a)(p2 - (double)tr[j+1].b)(p2 - (double)tr[j+1].c)); if (s1 > s2) { triangle temp; temp = tr[j]; tr[j] = tr[j+1]; tr[j+1] = temp; } } } }