stevenhalim / cpbook-code

CP4 Free Source Code Project (C++17, Java11, Python3 and OCaml)
2k stars 493 forks source link

Geometry - Wrong order in result after sorting #100

Open wahyudierwin opened 2 years ago

wahyudierwin commented 2 years ago

In this main code, https://github.com/stevenhalim/cpbook-code/blob/f8f34ba6f096d30360f48575405ae99e764f41f7/ch7/points_lines.java#L174-L180

i changed into

point[] P = new point[7];
P[0] = new point(3.6, 4.5);
P[1] = new point(0, 2);
P[2] = new point(1.75, 6.75);
P[3] = new point(2.4, 3);
P[4] = new point(5.6, 5.8);
P[5] = new point(0.5, 1.5);
P[6] = new point(4.75, 2.1);

And the result after Arrays.sort(P) is

(0.00, 2.00)
(0.50, 1.50)
(1.75, 6.75)
(2.40, 3.00)
(3.60, 4.50)
(5.60, 5.80)
(4.75, 2.10)

Shouldn't the (4.75, 2.10) appear before (5.60, 5.80)?