Algorithm for arranging Cartesian points

Viewed 810

I have few Cartesian points of the form : (x,y)
where x and y both are non-negative integers.

For e.g.
(0,0) , (1,1), (0,1)

I need an algorithm to arrange the above points
in such a way that going from one point to other
changes either x or y by 1.

In other words, I would like to avoid
diagonal movement.

So, the above mentioned points will be arranged like :
(0,0), (0,1), (1,1).

Similarly for (0,0),(1,1),(0,2)
there is no such arrangement possible.

I am not sure about what to call it
but I would call it Manhattan ordering.

Can anyone help?

6 Answers
Related