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

原始代码如下:

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]);
    }
}

你可能感兴趣的:(输入数字)