You are viewing a single comment's thread. Return to all comments →
trivial with qsort from stdlib.h.
also, note it's possible to completely avoid using doubles when computing the area, by "integerizing" the heron area formula
int heron(triangle *t){ int twop=t->a+t->b+t->c; return twop*(twop-2*t->a)*(twop-2*t->b)*(twop-2*t->c); } int heron_comp(const void *a, const void *b){ return heron((triangle*)a) - heron((triangle*)b); } void sort_by_area(triangle* tr, int n) { qsort(tr, n, sizeof(*tr), heron_comp); }
Seems like cookies are disabled on this browser, please enable them to open this website
An unexpected error occurred. Please try reloading the page. If problem persists, please contact support@hackerrank.com
Small Triangles, Large Triangles
You are viewing a single comment's thread. Return to all comments →
trivial with qsort from stdlib.h.
also, note it's possible to completely avoid using doubles when computing the area, by "integerizing" the heron area formula