Sorting

Hi...

I've use this code to define a new structure. Here's my code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
struct drag
{
	int x, y;
	drag (int _x = 0, int _y = 0)
	{
		x = _x;
		y = _y;
	}
	bool operator <(const drag &two) const
	{
		if (x == two.x)
			return y >= two.y;
		return x < two.x; 
	}
};

when I want to sort an array of these structure, it fails to sort (it fails at the structure with the same x and y e.g. for these structure d1(0, 1),d2(0, 1),...). I've tried to replace ">=" in my operator overloading in this structure with ">" and finally sorting goes right and sorted my array correctly! But what's the matter with ">="? Could anyone explain it?

Please help me to get it! I'm waiting for your answers ;)
Thanks.
Last edited on
Topic archived. No new replies allowed.