What is the best way to sort the points(first based on x co-ordinate and if x is same then on y co-ordinate and if y is same then based on z co-ordinate and so on.) in java without implementing sorting algorithm?
In c++ it can be done very easily(as follows) with the help of pairs.
For 2D:
Vector < pair < int,int > > plane;
sort(plane.begin(),plane.end())
For 3D:
Vector < pair < int,pair < int,int > > > space;
sort(space.begin(),space.end());
Thanks in Advance.
Shantanu
You don’t need to implement a sorting algorithm. You just need to implement a comparator, which can then be used with
Collections.sort().See Object Ordering from the Java Tutorial for more information.