# Question:Sorting a list of xy pairs

## Question:Sorting a list of xy pairs

I was trying to locate a good simple sorting method and found one however in attempts to use it, it appears not to work the way I had expected.

a := [[1, 7], [2, 3], [5, 4], [1, 2], [8, 9], [7, 9], [1, 6]]:

In hopes to sort the x position in order and in the event that there existed x positions the same I thought I might sort the y position first so that the order for the y position would be set and then all that would be needed was to sort the x and I would be set.  Unfortunately it didn't work.  I expected maple to hold the lists as they were presented and as I show it didn't matter that I sorted the y positions first.

b := sort(a, (x, y) -> evalb(x[2] < y[2]) )  # First sort the y positions of a

b := [[1, 2], [2, 3], [5, 4], [1, 6], [1, 7], [7, 9], [8, 9]]

sort(a, (xo, yo) -> evalb(xo[1] < yo[1]) )  # Second sort the x positions of b

[[1, 6], [1, 2], [1, 7], [2, 3], [5, 4], [7, 9], [8, 9]]

I had expected that [1,2] would stay in front of [1,6] as Maple had ordered them in b.  So when I sorted b (because it is a list) I had thought Maple would just systematically shuffle them accordingly.

Am I right to say that in this case Maple uses memory locations using sort regardless of it being a list?  and how can I sort it ?

﻿