DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Aniruddha has posted 40 posts at DZone. View Full User Profile

Bubble Sort - C#

06.04.2012
| 5405 views |
  • submit to reddit
public int[] BubbleSort(int[] _arr)
        {
            for (int i = _arr.Length - 1; i > 0; i--)
            {
                for (int j = 0; j < i; j++)
                {
                    if (_arr[j] > _arr[j + 1])
                    {
                        int temp = _arr[j];
                        _arr[j] = _arr[j + 1];
                        _arr[j + 1] = temp;
                    }
                }
            }
            return _arr;
        }

Bubble Sort -  C#

Efficiency - O(n^2)