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("排序前的數(shù)組:");
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("排序后的數(shù)組:");
foreach(int item in arr)
{
Console.Write(item+" ");
}
Console.WriteLine();
Console.ReadKey();
}
}
}
相關(guān)文章
FtpHelper實(shí)現(xiàn)ftp服務(wù)器文件讀寫操作(C#)
這篇文章主要為大家詳細(xì)介紹了FtpHelper實(shí)現(xiàn)ftp服務(wù)器文件讀寫操作,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-03-03Unity實(shí)現(xiàn)簡(jiǎn)單的虛擬搖桿
這篇文章主要為大家詳細(xì)介紹了Unity實(shí)現(xiàn)簡(jiǎn)單的虛擬搖桿,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2020-04-04C#把數(shù)字轉(zhuǎn)換成大寫金額的代碼實(shí)例
這篇文章主要介紹了C#把數(shù)字轉(zhuǎn)換成大寫金額的代碼實(shí)例,例如把200轉(zhuǎn)換成“貳佰元”,需要的朋友可以參考下2014-05-05C# WinForm創(chuàng)建Excel文件的實(shí)例
下面小編就為大家?guī)?lái)一篇C# WinForm創(chuàng)建Excel文件的實(shí)例。小編覺得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過來(lái)看看吧2017-01-01C#窗體編程(windows forms)禁止窗口最大化的方法
這篇文章主要介紹了C#窗體編程(windows forms)禁止窗口最大化的方法,以及避免彈出系統(tǒng)菜單和禁止窗口拖拽的方法,需要的朋友可以參考下2014-08-08