BUBBLE SORT
namespace BubbleSort
{
class Program
{
public static void BubbleSort(int[] Arr)
{
int temp = 0;
for (int i = 0; i < Arr.Length-1; i++)
{
for (int j = 0; j < Arr.Length - i - 1; j++)
{
if (Arr[j] > Arr[j + 1])
{
temp = Arr[j];
Arr[j] = Arr[j + 1];
Arr[j + 1] = temp;
}
}
}
}
static void Main(string[] args)
{
int[] Arr = { 20, 15, 14, 13, 10, 7, 8, 5, 4, 2, 0, -10 };
BubbleSort(Arr);
foreach (int x in Arr)
{
Console.WriteLine(x);
}
}
}
}
No comments:
Post a Comment