برنامه (الگوریتم) مرتب سازی حبابی در سی شارپ

با استفاده از کد زیر می توانید هر آرایه ی عددی یا غیرعددی (مقایسه بر اساس کد اسکی کاراکترها) را به صورت صعودی یا نزولی با الگوریتم مرتب سازی حبابی  ، مرتب کنید .

using System;

namespace BubbleSortInCSharp
{
    class bubblesort
    {
        static void Main(string[] args)
        {
            int[] a = { 3, 2, 5, 4, 1 }; // passing numbers through array
            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("This Application Created by vithal wadje for C# corner");
            Console.WriteLine("The Sorted array");
            foreach (int aa in a) //writting array
                Console.Write(aa + " ");
            Console.Read();
        }
    }
}