You need to specify exactly how you store your coordinate group.
The easiest way is to save them as the new structure you are creating and apply the basic algorithm for sorting bubbles on top of it, using the Y value as the sort parameter. Then, when you βchangeβ the position of the structures, X and Y stay together.
struct Vector { float x; float y; };
source share