Hello,

I was solving this problem. In this I have sorted the array of structures.

```
//This is my structure:
typedef struct node
{
int a,b,c;
} node;
```

```
//This gets runtime error on test-32.
//Error: comparison doesn't meet irreflexive requirements, assert(!(a < a)).
bool compare(node n1, node n2)
{
if(n1.c > n2.c) return false;
else return true;
}
```

```
//However this gets accepted, only change is in >=
bool compare(node n1, node n2)
{
if(n1.c >= n2.c) return false;
else return true;
}
```

Why is this error coming? I thought even if we give only > then for equal value it will return true, so there should not be any problem between comparison of equal elements.

Thank you

because if

x=ythen bothx<yandy<xaccording to your first submission. It causes UB while sorting.I am sorry, but can you explain where both x<y and y<x are happening? In the compare function if x==y, then it returns true (meaning that x will come before y) but since they are same then it does not matter.

And also

x=ymeans thatycomes beforex. It should return false ifx=y.Your function says that

a<afor anya. Such a function can't be a comparatorThank you, I understand where I was making mistake.

The comparator function in

stl::sort()follows and requires strict weak ordering.eg. Consider Comp for ascending order:

And This is what you are doing :

Your accepted solution solves this problem and that is why it is not throwing any error.

Thanks a lot! I didn't knew about strict weak ordering.