基于顺序表的合并排序:
//基于顺序表的合并排序
static private SequenceList<int> Merge(SequenceList<int> s1,SequenceList<int> s2)
{
SequenceList<int> sList = new SequenceList<int>(20);
int i = 0;
int j = 0;
while(i<=s1.PointerLast&&j<=s2.PointerLast)
{
if (s1[i] < s2[j])
{
sList.Add(s1[i]);
i++;
}
else
{
sList.Add(s2[j]);
j++;
}
}
if (i > s1.PointerLast)
{
while (j <= s2.PointerLast)
{
sList.Add(s2[j]);
j++;
}
return sList;
}
else//即j>s2.PointerLast
{
while (i <= s1.PointerLast)
{
sList.Add(s1[i]);
i++;
}
return sList;
}
}
希望本文所述对大家C#程序设计有所帮助。
注:相关教程知识阅读请移步到c#教程频道。










