Thursday, 16 October 2014

Program for Bubble Sort in C#.NET

using System;

class myclass
{
    static void Main()
    {
        int[] a = { 4, 6, 9, 83, 34, 45 };
        int temp;

        for (int pass = 1; pass <= a.Length - 2; pass++)
        {
            for (int i = 0; i <= a.Length - 2; i++)
            {
                if (a[i] > a[i + 1])
                {
                    temp = a[i + 1];
                    a[i + 1] = a[i];
                    a[i] = temp;
                }

            }

        }

        Console.WriteLine("The Sorted array");
        foreach (int aa in a)
            Console.Write(aa + " ");

        Console.Read();
    }
}

No comments:

Post a Comment