Hideki Snk

Hideki Snk

  • NA
  • 5
  • 0

how to sort this kind of array?

Oct 13 2007 2:45 PM
Okay.. now i need help to sort this kind of array.. as u can see.. i wan all element in the same row followed the 1st element in the array..  but the problem is.. the source code is too long.. is there any way to cut down the code to be more simple?
here is mine..
int temp = 0, p = 0, l = 0, k = 0;
        int[,] arr = new int[2, 3] { { 100, 3, 2 }, { 10, 11, 12 } };
        for (int i = 0; i < 2; i++)
            for (int j = 0; j < 3; j++)
            {
                if (arr[p, l] > arr[p + 1, l])
                {
                    temp = arr[p + 1, l];
                    arr[p + 1, l] = arr[l, l];
                    arr[l, l] = temp;

                    temp = arr[p + 1, p + 1];
                    arr[p + 1, p + 1] = arr[l, p + 1];
                    arr[l, p + 1] = temp;

                    temp = arr[p + 1, p + 2];
                    arr[p + 1, p + 2] = arr[l, p + 2];
                    arr[l, p + 2] = temp;
                }
                Console.Write("{0} ", arr[i, j]);
                k++;
                if (k >= 3)
                {
                    Console.WriteLine();
                    k = 0;
                }
            }
please help me..i already tired thinking about it..

Answers (3)