从大到小排序,删除重复项
#region
static void Main(string[] args)
{
int[] a = new int[] { 10, 2, 9, 3, 5, 6, 3, 3, 3, 3, 33, 5, 8, 8, 1, 10, 8, 8, 3 };
int[] b = new Program().sortAndDistinctArray(a);
for (int z = 0; z < b.Length; z++)
{
Console.WriteLine(b[z]);
}
Console.ReadKey();
}
public int[] sortAndDistinctArray(int[] a)
{
int[] b = new int[a.Length];
int alndex = 0, blndex = 0;
int dupli = 0;
b[blndex++] = a[alndex++];
while (alndex < a.Length)
{
Boolean isDupli = false;
for (int i = 0; i < blndex; i++)
{
if (b[i] == a[alndex])
{
alndex++;
dupli++;
isDupli = true;
break;
}
}
if (!isDupli)
b[blndex++] = a[alndex++];
}
int[] c = new int[a.Length - dupli];
System.Array.Copy(b, 0, c, 0, b.Length - dupli);
for (int i = 0; i < c.Length; i++)
{
for (int j = 0; j < c.Length; j++)
{
if (c[i] > c[j])
{
int temp = c[i];
c[i] = c[j];
c[j] = temp;
}
}
} return c;
}

浙公网安备 33010602011771号