您的位置:首页 > 其它

使用“冒泡法”对输入数字进行排序

2007-11-07 10:30 661 查看
原始代码如下:

using System;

using System.Data;

using System.Configuration;

using System.Web;

using System.Web.Security;

using System.Web.UI;

using System.Web.UI.WebControls;

using System.Web.UI.WebControls.WebParts;

using System.Web.UI.HtmlControls;

public partial class _Default : System.Web.UI.Page

{

protected void Page_Load(object sender, EventArgs e)

{

}

public void Sort(int[] list)//构造方法,对数组进行排序

{

int j = 1;

int temp = 0;

while (j < list.Length)

{

for (int i = 0; i < list.Length - j; i++)

if (list[i] > list[i + 1])

{

temp = list[i];

list[i] = list[i + 1];

list[i + 1] = temp;

}

j++;

}

}

protected void Button1_Click(object sender, EventArgs e)

{

int[] iArrary = new int[] { Convert.ToInt32(TextBox1.Text), Convert.ToInt32(TextBox2.Text), Convert.ToInt32(TextBox3.Text), Convert.ToInt32(TextBox4.Text), Convert.ToInt32(TextBox5.Text) };

_Default sh = new _Default();

sh.Sort(iArrary);

for (int m = 0; m < iArrary.Length; m++)

Response.Write(iArrary[m]);

}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐