using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp9
{
class Program
{
static void Main(string[] args)
{
int[] src = new int[] { 2, 1, 0, 4, 1, 3, 3, -1, -1 };
List<int> idxArr = new List<int>();
for (int i = 0; i < src.Length; i++)
{
int index = 0;
int val = src[index];
while (idxArr.Contains(index))
{
index++;
val = src[index];
}
for (int j = 0; j < src.Length; j++)
{
if (idxArr.Contains(j))
{
continue;
}
if (src[j] < val)
{
index = j;
val = src[j];
}
}
idxArr.Add(index);
}
foreach (int idx in idxArr)
{
Console.Write(src[idx] + " ");
}
Console.WriteLine();
foreach(int idx in idxArr)
{
Console.Write(idx + " ");
}
Console.WriteLine();
Console.ReadKey();
}
}
}
输出:
-1 -1 0 1 1 2 3 3 4
7 8 2 1 4 0 5 6 3