当前位置:首页 > 开发 > C# > 正文内容

C# 冒泡排序

C#3年前 (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];
			*/
        }
    }
}


转载请注明出处。

本文链接:http://pythonopen.com/?id=239

相关文章

ListView RetrieveVirtualListItem 事件需要每个 ListView 列的列表视图子项。”

System.InvalidOperationException:“处于 VirtualMode 中...

C#解析Torrent获取磁力链

NuGet添加 MonoTorrentusing MonoTorrent;string&n...

C# System.IO.Path

System.IO.Path.GetExtension返回指定的路径字符串的扩展名。string&n...

C# Winform 拖放文件

private void Form1_Load(object send...

C# Browsable(bool)

在编程中(比如常见的 C# 语言在开发 Windows Forms 等应用程序时),Browsabl...

C# decimal

概述在 C# 中,decimal是一种数据类型,用于表示高精度的十进制数值。它主要用于需要精确计算的...