标签:
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApplication1 { class Program { static void Main(string[] args) { int[] a = { 1, 5, 7, 12 }; int[] b = { 2, 6, 8, 9 }; int len = a.Length + b.Length; int[] c = new int[len]; int v1_index = 0; int v2_index = 0; int index = 0; while (index <= len) { if (a[v1_index] < b[v2_index]) { c[index++] = a[v1_index]; v1_index++; } else if (a[v1_index] == b[v2_index]) { c[index++] = a[v1_index]; c[index++] = b[v2_index]; v1_index++; v2_index++; } else { c[index++] = b[v2_index]; v2_index++; } if (v1_index == a.Length || v2_index == b.Length) { break; } } if (v1_index == a.Length) { for (int i =v2_index; i < b.Length; i++) { c[index++] = b[i]; } } else { for (int i = v1_index; i < a.Length; i++) { c[index++] = a[i]; } } } } }
标签:
原文地址:http://www.cnblogs.com/kexb/p/5576018.html