namespace 冒泡排序
{
class program
{
static void swap( ref int atemp, ref int btemp)//注意ref的使用
{
int temp = atemp;
atemp = btemp;
btemp = temp;
}
static void main(string[] args)
{
int temp=0;
int[]arr={23,44,66,76,98,11,3,9,7};
console.writeline("排序前的数组:");
foreach(int item in arr)
{
console.write(item+" ");
}
console.writeline();
for(int i=0;i<arr.length-1;i++)
{
for(int j=0;j<arr.length-1-i;j++)
{
if (arr[j] > arr[j + 1])
swap( ref arr[j], ref arr[j + 1]);
}
}
console.writeline("排序后的数组:");
foreach(int item in arr)
{
console.write(item+" ");
}
console.writeline();
console.readkey();
}
}
}
如对本文有疑问, 点击进行留言回复!!
使用Visual Studio2019创建C#项目(窗体应用程序、控制台应用程序、Web应用程序)
C#实现获取本地内网(局域网)和外网(公网)IP地址的方法分析
网友评论