using System;
using System.Collections;
using System.Linq;
using System.Text;namespace ConsoleApplication30
{
class Program
{
static void Main(string[] args)
{
ArrayList a = new ArrayList();
string num;
while(true)
{
Console.WriteLine("Enter One Number");
num = Console.ReadLine();
if (num.Equals("e"))
{
break;
}
a.Add(num); }
// paixu
for (int i = 1; i < a.Count; i++)
{
for (int j = a.Count - 1; j >= i;j-- )
{
if (int.Parse("a[j]")>int.Parse("a[j-1]"))
{
int t = int.Parse("a[j]");
a[j] = a[j - 1];
a[j - 1] = t;
}
}
}
// print
for (int i = 0; i < a.Count; i++)
{
Console.WriteLine(a[i]);
}
}
}
}
自己改不了啦 改正错误 求正解
using System.Collections;
using System.Linq;
using System.Text;namespace ConsoleApplication30
{
class Program
{
static void Main(string[] args)
{
ArrayList a = new ArrayList();
string num;
while(true)
{
Console.WriteLine("Enter One Number");
num = Console.ReadLine();
if (num.Equals("e"))
{
break;
}
a.Add(num); }
// paixu
for (int i = 1; i < a.Count; i++)
{
for (int j = a.Count - 1; j >= i;j-- )
{
if (int.Parse("a[j]")>int.Parse("a[j-1]"))
{
int t = int.Parse("a[j]");
a[j] = a[j - 1];
a[j - 1] = t;
}
}
}
for (int i = 0; i < a.Count; i++)
{
Console.WriteLine(a[i]);
}
}
}
}
自己改不了啦 改正错误 求正解
{
int t = Convert.ToInt(a[j]);//可能是int32
a[j] = a[j - 1];
a[j - 1] = t;
}
ArrayList a = new ArrayList();
改成用泛型
List<int> a = new List<int>();if (a[j])>a[j-1]) //使用泛型的话 就不用转类型了
{
int t = a[j];
a[j] = a[j - 1];
a[j - 1] = t;
}