【发布时间】:2014-11-06 22:31:43
【问题描述】:
我想让用户输入数字,然后用冒泡排序对其进行排序,但我没有找到正确的实现:/
class bubblesort
{
static void Main(string[] args)
{
int[] a = new int[5];
int t;
for (int p = 0; p <= a.Length - 2; p++)
{
for (int i = 0; i <= a.Length - 2; i++)
{
if (a[i] > a[i + 1])
{
t = a[i + 1];
a[i + 1] = a[i];
a[i] = t;
}
InputStudent(a[i]);
}
}
Console.WriteLine("The Sorted array");
foreach (int aa in a)
{
Console.Write(aa + " ");
}
Console.Read();
}
static void InputStudent(int p)
{
Console.WriteLine("Enter the Number");
p = int.Parse(Console.ReadLine());
Console.WriteLine();
}
public static int i { get; set; }
}
【问题讨论】:
-
有什么问题?
-
用户输入数字后输出排序数组 0 0 0 0 0 !
-
为什么不先要求#s,然后进行排序?在排序中间请求 #s 真的没有意义。
-
另外,您的输入学生函数似乎没有做任何事情。你传入一个 int,然后你从用户那里得到一个 int,然后你在方法内部做一个本地分配,一旦方法范围结束,它就会消失)
-
我投票决定保持开放状态。这个问题问得不好,就其本身而言,我同意以“不清楚你在问什么”来结束,但答案很好。
标签: c# arrays algorithm sorting