using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SortingBubbleSort
{
class Program
{
static void Main(string[] args)
{
//a temporary int, to store a value when switching positions
int temp = 0;
//DATA : list of sortable items
int[] data = { 89, 76, 45, 92, 67, 12, 99 };
for (int outer = 0; outer < data.Length; outer++)
{
for (int inner = 0; inner < data.Length - 1; inner++)
{
////comparison statement
if (data[inner] > data[inner + 1])
{
temp = data[inner + 1];
data[inner + 1] = data[inner];
//switching operation
data[inner] = temp;
}
}
}
//Sorted array
foreach (int i in data)
{
Console.Write("\t{0}",i);
}
Console.Read();
} }
}
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SortingBubbleSort
{
class Program
{
static void Main(string[] args)
{
//a temporary int, to store a value when switching positions
int temp = 0;
//DATA : list of sortable items
int[] data = { 89, 76, 45, 92, 67, 12, 99 };
for (int outer = 0; outer < data.Length; outer++)
{
for (int inner = 0; inner < data.Length - 1; inner++)
{
////comparison statement
if (data[inner] > data[inner + 1])
{
temp = data[inner + 1];
data[inner + 1] = data[inner];
//switching operation
data[inner] = temp;
}
}
}
//Sorted array
foreach (int i in data)
{
Console.Write("\t{0}",i);
}
Console.Read();
} }
}
output:-
12 45 67 79 89 92 99