I am doing some sort operation and the data structure that I am using is a List<Point>
.
Now this Point has two values x
and y
, and the values are given not in a sorted manner.
I have to sort this List<Point>
in an efficient way according to the value of x, either increasing x or decreasing x.
One solution can be a brute force approach of parsing through each value and comparing that value to all the other to find the smallest in each iteration but that will be an inefficient approach.
What other solution can be used for this problem.
Edit : Point is from org.opencv.core
package.
Point class
and override theequals()/hashcode()
and other operators then just apply sort. Or you can useMap
class available.