Programming Alogorithm Series: Bubble Sort
using System;
namespace BubbleSort
{
class Program
{
static void Main(string[] args)
{
int[] array = new int[] {2,5,7,1,9,0,3,4,2,6,7,5};
// Before sorting
for (int i = 0; i < array.Length - 1; i++)
{
Console.Write(array[i]);
}
Console.ReadLine();
ArraySort.SortArray(array);
// After sorting
for (int i = 0; i < array.Length - 1; i++)
{
Console.Write(array[i]);
}
Console.ReadLine();
}
}
class ArraySort
{
public static void SortArray(int[] numbers)
{
int tempInt;
for (int i = (numbers.Length-1); i >=0; i--)
{
for (int j =1; j <=i; j++)
{
if (numbers[j-1] > numbers[j])
{
tempInt = numbers[j-1];
numbers[j-1] = numbers[j];
numbers[j] = tempInt;
}
}
}
}
}
}