选择排序 + 冒泡排序一个随机填充的指定字节的数组
private static Byte[] arr = new Byte[5];
static void Main(string[] args)
{
Random random = new Random();
random.NextBytes(arr);
MaoPao();
XuanZe();
Console.ReadKey();
}
public static void XuanZe()
{
for (int i = 0; i < arr.Length; i++)
{
for (int j = i + 1; j < arr.Length; j++)
{
if (arr[i] > arr[j])
{
Byte b = 0;
b = arr[i];
arr[i] = arr[j];
arr[j] = b;
}
}
}
foreach (var item in arr)
{
Console.WriteLine(item);
}
}
public static void MaoPao()
{
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])
{
Byte b = 0;
b = arr[j];
arr[j] = arr[j + 1];
arr[j + 1] = b;
}
}
}
foreach (var item in arr)
{
Console.WriteLine(item);
}
}