Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions Small_Large_Triangles.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@

void swap(triangle* a,triangle* b)
{
triangle temp=*a;
*a=*b;
*b=temp;
}
int cmp(triangle tr)
{
int a=tr.a;
int b=tr.b;
int c=tr.c;
return (a+b+c)*(a-b+c)*(a+b-c)*(-a+b+c);
}
void sort_by_area(triangle* tr, int n) {
/**
* Sort an array a of the length n
*/
for(int i=0;i<n;i++)
{
int swapped=0;
for(int j=0;j<n-i-1;j++)
{
if(cmp(tr[j])>cmp(tr[j+1]))
swap(&tr[j],&tr[j+1]);
swapped=1;
}
if(swapped==0)
break;
}

}

// You can visit this link for question :-
// https://www.hackerrank.com/challenges/small-triangles-large-triangles/submissions/code/113637557