How do I keep the y coordinate with the x coordinate when bubble sorting

I am trying to sort x, y coordinates and am able to sort x column but not without losing the original y coordinate. How do I sort the x column while leaving the y coordinate intact with the x coordinate? Below is my function:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
  void s(int m[][2], int numRows)
{
	for (int i = 0; i < numRows; i++)
	{
		for (int j = 0; j < numRows -1; j++)
		{
			if (m[j][0] > m[j + 1][0])
			{
				int temp = m[j + 1][0];

				m[j+1][0] = m[j][0];

				m[j][0] = temp;
			}
		}
	}
}
Last edited on
use std::pair or write a small data class to encapsulate x and y.
Hmm... well I have not yet learned about classes. I guess this is the best way to go?

I will try it out. Thank You for the reply.
wait a minute, can't you just swap y when you are swapping x?
I think that is possible but I have not tried it.
Topic archived. No new replies allowed.