• 算法:给定两个已从小到大排好序的整型数组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();
            }
        }
    }
  • 相关阅读:
    WPF的布局--DockPanel
    WPF的布局--StackPanel
    C#中的不可空类型转为可空类型
    linux下安装nodejs及npm
    HTML DOM 事件对象 ondragend 事件
    pc端页面在移动端显示问题
    css设置文字上下居中,一行文字居中,两行或多行文字同样居中。
    超简单的gif图制作工具
    Git创建与合并分支
    props default 数组/对象的默认值应当由一个工厂函数返回
  • 原文地址:https://www.cnblogs.com/myself/p/1772727.html
Copyright © 2020-2023  润新知