Thursday, 29 October 2015

Bubble Sorting in C# .Net

Bubble Sorting in C# .Net


  1. Open Visual Studio from Start - All programs - Microsoft Visual Studio.
  2. Then go to to "File" - "New" - "Project..." then select Visual C# - Windows - Console application. 

#_Code
.......................................................................................................................................................................................................................................
static void Main(string[] args)
        {
            int[] a = { 23, 32, 15, 24, 14 };  
            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;
                    }
                }
            }
            Console.WriteLine("Simple Bubble Sort in C#");
            Console.WriteLine("The Sorted array");
            foreach (int aa in a)                         
                Console.Write(aa + " ");
            Console.Read();

        }
....................................................................................................................................................................................................................................
Unsorted Elements:-23, 32, 15, 24, 14

Sorted Elements :- 14, 15, 23, 24, 32






No comments:

Post a Comment

Factorial of a Number

Recently Viewed