在网页上的一个文本旷里输入整型数以,分隔如 3,5,56,5,565,56点提交按扭后排序,C#版本
private void Button1_Click(object sender, System.EventArgs e)
{
int[] myArray = new int[] { 10, 8, 3, 5, 6, 7, 4, 6, 9 };
// 取长度最长的词组 -- 冒泡法
for( int j=1;j<myArray.Length;j ++ )
{
for(int i=0;i<myArray.Length - 1;i ++)
{
// 如果 myArray[i] > myArray[i+1] ,则 myArray[i] 上浮一位
if( myArray[i]>myArray[i+1])
{
int temp = myArray[i];
myArray[i] = myArray[i+1];
myArray[i+1] = temp;
}
}
}
foreach(String name in myArray)
{
// ????怎么把排序显示出来?不知道怎么写
显示在一个Label上
}
}
private void Button1_Click(object sender, System.EventArgs e)
{
int[] myArray = new int[] { 10, 8, 3, 5, 6, 7, 4, 6, 9 };
// 取长度最长的词组 -- 冒泡法
for( int j=1;j<myArray.Length;j ++ )
{
for(int i=0;i<myArray.Length - 1;i ++)
{
// 如果 myArray[i] > myArray[i+1] ,则 myArray[i] 上浮一位
if( myArray[i]>myArray[i+1])
{
int temp = myArray[i];
myArray[i] = myArray[i+1];
myArray[i+1] = temp;
}
}
}
foreach(String name in myArray)
{
// ????怎么把排序显示出来?不知道怎么写
显示在一个Label上
}
}
string a="12";
int b=Convert.ToInt32(a);
主要是两个问题,1、一个是把字符串如(1,2,55,4)赋给数组
2、把排好序列的数组显示在LABEL上面
数组也是同样的道理;
如果你的字符串中有逗号,先把字符串中的数字取出来放到数组里面
string str = TextBox1.Text;
string[] myArray = str.Split(',');
foreach(string s in myArray)
{
int temp = int.Parse(s)
//
//...
//
}//second
Label1.Text =yourResultString;