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();
            }
        }
    }
  • 相关阅读:
    windows 物理内存获取
    windbg-.process切换进程(内核)
    cnetos 6.7彻底解决vmware NAT网络问题
    优秀的博客链接地址
    使用Spring MVC统一异常处理实战
    active mq 配置
    socket demo程序
    flume 中的 hdfs sink round 和roll
    软链接与硬链接
    flume A simple example
  • 原文地址:https://www.cnblogs.com/myself/p/1772727.html
Copyright © 2011-2022 走看看