110,571
社区成员
发帖
与我相关
我的任务
分享
static int[] QuickSort(int[] n)
{
int a = n.First();
int[] small={};
int[] lager = { };
for (int i = 1; i < n.Count(); i++)
{
if (n[i] <= a)
{
int[] s = new int[small.Count() + 1];
small.CopyTo(s, 0);
s[small.Count()] = n[i];
small = s;
}
else
{
int[] l = new int[lager.Count() + 1];
lager.CopyTo(l, 0);
l[lager.Count()] = n[i];
lager = l;
}
}
while (IsSort(small)==false)
{
small = QuickSort(small);
}
while (IsSort(lager)==false)
{
lager = QuickSort(lager);
}
int[] final=new int[small.Count() + lager.Count() +1];
small.CopyTo(final,0);
final[small.Count()]=a;
lager.CopyTo(final,small.Count()+1);
return final;
}
static bool IsSort(int[] n)
{
for (int i = 1; i < n.Count(); i++)
{
if (n[i] < n[i - 1])
{
return false;
}
}
return true;
}