c#冒泡排序算法示例
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
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();
}
}
}
相关文章
C#事务处理(Execute Transaction)实例解析
这篇文章主要介绍了C#事务处理(Execute Transaction)实例解析,对于理解和学习事务处理有一定的帮助,需要的朋友可以参考下2014-08-08
C#实现获取本地内网(局域网)和外网(公网)IP地址的方法分析
这篇文章主要介绍了C#实现获取本地内网(局域网)和外网(公网)IP地址的方法,结合实例形式总结分析了C#获取IP地址相关原理、实现方法与操作注意事项,需要的朋友可以参考下2020-03-03
深入理解C#中new、override、virtual关键字的区别
下面小编就为大家带来一篇深入理解C#中new、override、virtual关键字的区别。小编觉得挺不错的,现在就分享给大家,也给大家做个参考。一起跟随小编过来看看吧2016-06-06


最新评论