public int[] min(int[] a){int temp, swaps;for (int i = 0; i < a.Length; i++){swaps = 0;for (int j=0;j a[j + 1]){temp = a[j];a[j] = a[j+1];a[j + 1] = temp;swaps++;}}if (swaps == 0){break;}}return a;}
public static string BubbleSort() { int[] arr = { 78, 55, 45, 98, 13 }; int temp; for (int j = 0; j <= arr.Length - 2; j++) { for (int i = 0; i <= arr.Length - 2; i++) { if (arr[i] > arr[i + 1]) { temp = arr[i + 1]; arr[i + 1] = arr[i]; arr[i] = temp; } } } Console.WriteLine("Sorted:"); foreach (int p in arr) Console.Write(p + " "); Console.Read(); }
public static string BubbleSort()
{
int[] arr = { 78, 55, 45, 98, 13 };
int temp;
for (int j = 0; j <= arr.Length - 2; j++)
for (int i = 0; i <= arr.Length - 2; i++)
if (arr[i] > arr[i + 1])
temp = arr[i + 1];
arr[i + 1] = arr[i];
arr[i] = temp;
}
Console.WriteLine("Sorted:");
foreach (int p in arr)
Console.Write(p + " ");
Console.Read();