题目:有一组数据3,5,9,7,4,13,15,0,2,20.已知最大数是20,把数据从小到大排序,而且算法复杂度只能是1
代码
public void Sort()
{
int[] a ={ 3, 5, 9, 7, 4, 13, 15, 0, 2, 20 };
bool[] b = new bool[21];
for (int i = 0; i < a.Length; i++)
{
b[a[i]] = true;
}
for (int i = 0; i < b.Length; i++)
{
if (b[i])
Console.WriteLine(i + ",");
}
Console.ReadLine();
}
{
int[] a ={ 3, 5, 9, 7, 4, 13, 15, 0, 2, 20 };
bool[] b = new bool[21];
for (int i = 0; i < a.Length; i++)
{
b[a[i]] = true;
}
for (int i = 0; i < b.Length; i++)
{
if (b[i])
Console.WriteLine(i + ",");
}
Console.ReadLine();
}
有点意思