数组排序问题。。。新手
using System;class Program
{
static void Main(string[] args)
{
int[] a = new int[] { 3, 5, 7, 8, 3, 2, 3, 45, 76, 21 };
for (int i = 0; i < a.Length; i++)
{
for (int t = 1; t <a.Length; t++)
{
if (a[i]> a[t])
{
int n;
n = a[i];
a[i] = a[t];
a[t] = n;
}
}
}
for (int m = 0; m < a.Length; m++)
{
Console .Write (a[m]+" ");
}
}
}
为什么我输出的结果不是升序? 好像没错亚 --------------------编程问答-------------------- 明白了。。。。。。。 --------------------编程问答--------------------
for (int t = i+1; t < a.Length; t++)--------------------编程问答-------------------- 代码有点问题啊,二楼已指出…… --------------------编程问答-------------------- using System;
using System.Collections.Generic;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
int[] a = new int[] { 3, 5, 7, 8, 3, 2, 3, 45, 76, 21 };
for (int i = 0; i < a.Length; i++)
{
for (int t = 0; t < a.Length; t++)
{
if (a[i] < a[t])
{
int n;
n = a[i];
a[i] = a[t];
a[t] = n;
}
}
}
for (int m = 0; m < a.Length; m++)
{
Console.Write(a[m] + " ");
}
System.Console.Read();
}
}
}
补充:.NET技术 , C#