12
Answers

Sorting strings (C#).

Muhammad Adeel

Muhammad Adeel

10y
1.5k
1

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)
Next Recommended Forum