hi,i m new.i have an assignment that need to sort a group of points.
the points are in 3d coordinate system.
May anyone help me?
give some suggestion on how to do it.
i know how to sort a group of number,but i have no any idea how to sort a group of points by ascending.
Thanks for your helping.
To sort any objects you need a comparison criteria. In the case of numbers, it is obviously operator <. In the case of points, there is no obvious way. You could sort them by x coordinate then by y (if x1==x2), then by z. You could sort them by the distance from some other point. You could sort them by x+y+z and etc. All of these are the same algorithm, with < replaced by a call to another function bool less(mystruct a, mystruct b). This is probably a part of another assignment. The whole text should give you an idea how to compare two points in a meaningful way.
I think besides an operator < you would also overload an operator ==. With these 2 operators overloaded, the sort function can figure out the rest of the comparison criteria like < <= == > >=
@sohguanh, a == b = !(a<b || b<a). Though I do understand this is up to twice as slow as writing your own ==. On the other hand, sorting doesn't involve much ==, does it?