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); }
Agh, the type casting for p! Got me.
got me the first time too :)
Prefer a faster sorting algorithm like quicksort or heapsort
Seems like cookies are disabled on this browser, please enable them to open this website
I agree to HackerRank's Terms of Service and Privacy Policy.
Small Triangles, Large Triangles
You are viewing a single comment's thread. Return to all comments →
Solution using bubble sort
Agh, the type casting for p! Got me.
got me the first time too :)
Prefer a faster sorting algorithm like quicksort or heapsort