Implementing Bubble Sort in C#
Code: CSharp
/*
** Simple class to sort an array in ascending order using bubble sort
** @author: Tanaz Kerawala
** @author: S Pradeep
** @date: 5/29/2007
*/
using System;
class AscendingBubbleSort
{
public static void Main()
{
int i,j,t;
int []p=new int[10];
int []q=new int[10];
int []c=new int[20];
for(i=0;i<10;i++)
{
Console.WriteLine("Enter Value");
p[i]=int.Parse(Console.ReadLine());
}
for(i=0;i<10;i++)
{
Console.WriteLine("Enter Value");
q[i]=int.Parse(Console.ReadLine());
}
if(j<10)
c[j]=p[j];
else
c[j]=q[j-10];
// Sorting: Bubble Sort
for(i=0;i<20;i++)
{
for(j=0;j<20;j++)
{
if(c[i]>c[j])
{
t=c[i];
c[i]=c[j];
c[j]=t;
}
}
}
// Print the contents of the sorted array
for(i=0;i<20;i++)
{
Console.WriteLine (c[i]);
}
}
}


