سلام دوستان عزیز . در این تاپیک ، کدمرتب سازی حبابی (Bubble sort) در سی شارپ رو براتون آماده کردم.
class BubbleSort
{
public void BubbleSorting()
{
int[] a = { 3, 2, 5, 4, 1 };
int t;
for (int p = 0; p <= a.Length - 2; p++)
{
for (int i = 0; i <= a.Length - 2; i++)
{
if (a[i] > a[i + 1])
{
t = a[i + 1];
a[i + 1] = a[i];
a[i] = t;
}
}
}
Console.WriteLine("The Sorted array");
foreach (int aa in a)
Console.Write(aa + " ");
Console.ReadLine();
}
}
{
public void BubbleSorting()
{
int[] a = { 3, 2, 5, 4, 1 };
int t;
for (int p = 0; p <= a.Length - 2; p++)
{
for (int i = 0; i <= a.Length - 2; i++)
{
if (a[i] > a[i + 1])
{
t = a[i + 1];
a[i + 1] = a[i];
a[i] = t;
}
}
}
Console.WriteLine("The Sorted array");
foreach (int aa in a)
Console.Write(aa + " ");
Console.ReadLine();
}
}
کدهای فایل Program.cs:
static void Main(string[] args)
{
{