namespace Sort
{
class Program
{
static void Main(string[] args)
{
/*
* 给定两个已从小到大排好序的整型数组arrA和arrB
* 将两个数组合并成arrC,使得arrC也要按从小到大的顺序排好序
*/
int[] arrA = new int[] { 1, 3, 5, 9, 10 };
int[] arrB = new int[] { 2, 4, 6, 7, 8 };
int[] arrC = new int[arrA.Length + arrB.Length];
int k = 0;
int m = 0;
int n = 0;
for (int i = m; i < arrA.Length; i++)
{
for (int j = n; j < arrB.Length; j++)
{
if (arrA[i] < arrB[j])
{
arrC[k++] = arrA[i];
m++;
n = j;
if (i == arrA.Length - 1)
{
for (int x = j; x < arrB.Length; x++)
{
arrC[k++] = arrB[x];
}
}
break;
}
else
{
arrC[k++] = arrB[j];
m = i;
n++;
if (j == arrB.Length - 1)
{
for (int x = i; x < arrA.Length; x++)
{
arrC[k++] = arrA[x];
}
}
continue;
}
}
}
for (int i = 0; i < arrC.Length; i++)
{
Console.WriteLine(arrC[i]);
}
Console.Read();
}
}
}