使用“冒泡法”对输入数字进行排序
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]);
}
}
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]);
}
}
相关文章推荐
- 输入三个数字使用指针进行排序(冒泡原理)
- 使用for循环对数组进行排序[冒泡法]
- 实战c++中的vector系列--使用sort算法对vector<unique_ptr<string>>进行排序(sort函数出错“应输入 2 个参数,却提供了 3 个)
- 使用sort()函数对数组中的数字进行排序。
- C++实现对输入数字组进行排序
- List的排序。在一个list里面放入"1","2"..."10","11"...,"99999","100000",使用字符串大小的顺序与解析成的数字的大小进行排序
- 实战c++中的vector系列--使用sort算法对vector<unique_ptr<string>>进行排序(sort函数“应输入 2 个参数,却提供了 3 个)
- 请对输入的一组数据(0~9)进行排序,规则:数据出现次数多的,数字大的排在前面。
- Java中使用Collections.sort()方法对数字和字符串泛型的LIst进行排序
- 使用Olami SDK实现一个语音输入数字进行24点计算的iOS程序
- 在Ruby中使用冒泡法进行排序
- 使用一维数组进行简单排序(冒泡法)
- 常见的出现login incorrect有下面几个原因: 1)大小写键盘问题,Ubuntu不认小键盘,所以一定要关掉NumLock,使用字母键盘上面的数字按键进行输入。
- 有一串字符串a12hh123mm21m78 ,请将其中的数字提取出来存入数组,使用选择排序算法将其进行排序:
- 使用Olami SDK实现一个语音输入数字进行24点计算的iOS程序
- Python 对输入的数字进行排序的方法
- 输入三个数字进行排序(冒泡原理)
- Python学习——对输入的数字进行排序
- (使用STL自带的排序功能进行排序)UVA 10905 Children's Game(求一组数据所能拼出的最大数字串)
- 初学python之练习将输入的数字进行排序的方法