Bubble sort in csharp


Bubble sort in c# + dry run using excel

Sorting a array using bubble sort


  public void PerformBubbleSort() {
            int temp = 0;
            int[] a = { 2, 4, 5, 1, 3 };
            for (int i = 0; i < a.Length; i++)
            {
                int last = (a.Length - 1) - i;
                for (int j = 0; j < last; j++)
                {
                    if (a[j] > a[j + 1])
                    {
                        temp = a[j];t
                        a[j] = a[j + 1];
                        a[j + 1] = temp;
                    }
                }
            }
        }

Output


Dry Run





Share on Google Plus

About myzingonline

Myzingonline is all about zing to share experience, knowledge, likes, dislikes and ideas of a person to the world.
    Blogger Comment
    Facebook Comment

0 comments:

Post a Comment