zoukankan      html  css  js  c++  java
  • 算法:给定两个已从小到大排好序的整型数组arrA和arrB,将两个数组合并成arrC,使得arrC也要按从小到大的顺序排好序

    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();
            }
        }
    }
  • 相关阅读:
    使用select2插件并添加拼音首字母检索
    sql id 或使用nolock
    .net 开源组件
    EF 创建数据库的策略 codefist加快效率!【not oringin!】
    个人拾遗!数组的拷贝等
    编程拾遗:集合类型的函数,返回值,如果没有,就返回默认集合new,或者 default(T)好一些。
    C# datatable to list
    npoi导出excel 导出List<T>
    display:inline、block、inline-block的区别 摘】
    ie下,jquery为动态添加的节点添加事件,用live
  • 原文地址:https://www.cnblogs.com/myself/p/1772727.html
Copyright © 2011-2022 走看看