手机
当前位置:查字典教程网 >编程开发 >C#教程 >c#冒泡排序算法示例
c#冒泡排序算法示例
摘要:复制代码代码如下:usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;...

复制代码 代码如下:

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#冒泡排序算法示例】相关文章:

C#排序算法之快速排序

C# 排序算法之堆排序

用C#写的ADSL拨号程序的代码示例

c# n个数排序实现代码

C#中方括号[]的语法及作用介绍

c#(Socket)异步套接字代码示例

c# 二分查找算法

c# 冒泡排序算法(Bubble Sort) 附实例代码

c#汉诺塔的递归算法与解析

c语言实现冒泡排序、希尔排序等多种算法示例

精品推荐
分类导航