当前位置:首页 > 编程语言 > C# > 正文内容

C# 冒泡排序

C#2年前 (2022-11-01)
int[] iage = { 11, 55, 44, 99, 77, 65, 13, 54, 65, 98, 874, 41, 12 ,87,654,21,98,7,41,3,65,98,32,12,15,48,79,46,12,13,64,8,99999,87,654,231,321,2,1,6,654,44,8,4,456,564};
for (int i = 0; i < iage.Length-1; i++)
{
    for (int j = 0; j < iage.Length-1-i; j++)
    {
        if (iage[j]>iage[j+1])
        {
			/*
			//使用临时变量
			int temp = iage[j ];
			iage[j] = iage[j+1];
			iage[j+1] = temp;
			*/

			/*
			//不使用临时变量
			iage[j] = iage[j] + iage[j + 1];
			iage[j + 1] = iage[j] - iage[j + 1];
			iage[j] = iage[j] - iage[j + 1];
			*/
        }
    }
}


相关文章

DotfuscatorPro使用教程

DotfuscatorPro使用教程

1首次使用,添加反编译工具路径ILASM_v4.0.30319C:\Windows\Microsof...

C# 时间操作

获取系统已运行时间    System.Environment.Tic...

C# NPOI

使用NPOI操作.xlsx以及其他格式的文档,并且无需安装OFFICE。实测无法加载带有密码的.xl...

C# 判断鼠标按键

private void button1_MouseDown(object&nb...

C# 获取网页源代码

private static string GetHtml(str...

C# 获取目录大小

public static long GetDirSize(strin...