I am using an arraylist of points. I need to sort it by the manhattan distance I found. I have been trying for days. Need major help.
The program prints :
[0] (25,-60) 85
[1] (59,-100) 159
[2] (-53,69) 122.
I need to Sort it by the values on the right- 122,150, 85.
So far i have:
The program prints :
[0] (25,-60) 85
[1] (59,-100) 159
[2] (-53,69) 122.
I need to Sort it by the values on the right- 122,150, 85.
So far i have:
public static void main(String[] args) throws Exception
{
ArrayList<Point> points = new ArrayList<Point>();
points = readPointsFromFile("points.txt");
showAllPoints(points);
}
public static ArrayList<Point> readPointsFromFile(String fileName)throws IOException
{
ArrayList<Point> points = new ArrayList<Point>();
File file = new File(fileName);
Scanner input = new Scanner(file);
while(input.hasNext())
{
points.add(new Point(input.nextInt(),input.nextInt()));
}
return points;
}
public static int cabDistance(Point point)
{
int x = Math.abs(point.x);
int y = Math.abs(point.y);
int sum = x + y;
System.out.println(sum);
return sum;
public static void bubbleSort(ArrayList<Point> list)
{
boolean swapped = true;
while (swapped)
{
swapped = false;
for (int a = 0; a < list.size()-1; a++)
{
if (list.get(a)(list.get(a+1)) > 0)
{
Item temp = list.get(a);
list.set(a, list.get(a+1));
list.set((a+1), temp);
swapped = true;
}
}
}
}
}
}