I want to sort a List of coordinates first by its x coordinates and and then by its y coordinates:
Orginal: (7,8)(10,22)(7,3)(5,10)(20,14)(7,10)(7,3)
First Step by x: (5,10)(7,8)(7,3)(7,10)(7,3)(10,22)(20,14)
Second Step by y: (5,10)(7,3)(7,3)(7,8)(7,10)(10,22)(20,14)
I have already a functions that works for the first step:
function SortCoords(Item1: Pointer; Item2: Pointer): Integer;
var
line1 : Coords;
line2 : Coords;
begin
line1 := Coords;(Item1);
line2 := Coords;(Item2);
if (line1.X < line2.X) then
result := -1
else if (line1.X > line2.X) then
result := 1
else
result := 0;
end;
But i dont get the second step.
If you want items sorted by a secondary key, this is only going to be important when the first keys are equal. In your example, this is the
result := 0;case.So something like this:
Might do what you want.