很久没复习了,这都能忘记,写了一下午,各种错误,伤不起呀 2个有序线性表合并,肯定有其中一个先合并完,没合并完的就依次填入。
static int[] sort(int[] a, int[] b) { int pa = 0, pb = 0, numbers = 0; int[] c = new int[a.Length + b.Length]; while (true) { if (pa < a.Length && pb < b.Length) { if (a[pa] < b[pb]) { c[numbers++] = a[pa++]; } else if (a[pa] > b[pb]) { c[numbers++] = b[pb++]; } else { c[numbers++] = a[pa++]; c[numbers++] = b[pb++]; } } else if (pa < a.Length) { while (pa < a.Length) { c[numbers++] = a[pa++]; } return c; } else if (pb < b.Length) { while (pb < b.Length) { c[numbers++] = b[pb]; } return c; } } }