Muhammad Adeel

Muhammad Adeel

  • NA
  • 55
  • 13.5k

Sorting strings (C#).

Sep 10 2014 1:50 PM

The following code is working perfectly for int array but i want to sort array string without using any built in library such as array.sort or .compareTo. so what should i change.

 int[] a = { 3, 2, 5, 4, 1 };
            int t;
            for (int p = 0; p <= a.Length - 2; p++)
            {
                for (int i = 0; i <= a.Length - 2; i++)
                {
                    if (a[i] > a[i + 1])
                    {
                        t = a[i + 1];
                        a[i + 1] = a[i];
                        a[i] = t;
                    }
                }
            }
            foreach (int aa in a)
                Console.Write(aa + " ");

Answers (12)