c#冒泡排序算法示例_C#教程-查字典教程网
c#冒泡排序算法示例
c#冒泡排序算法示例
发布时间:2016-12-28 来源:查字典编辑
摘要:复制代码代码如下: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#教程学习
    编程开发子分类