zoukankan      html  css  js  c++  java
  • La_Lb_Lc

    有数据类型为整型的顺序表La和Lb,其数据元素均按从小到大的升序排列,编写一个算法将它们合并成一个表Lc,要求Lc中数据元素也按升序排数据列。

    用数组实现的代码如下:

    static void Main(string[] args)
            {
                int[] La = { 1, 3, 5, 7, 9 };
                int[] Lb = { 2, 4, 6, 8, 10 };
                int[] Lc = new int[La.Length + Lb.Length];
                int i = 0;
                int j = 0;
                int k = 0;
                while ((i <= La.Length - 1) && (j <= Lb.Length - 1))
                {
                    if (La[i] <= Lb[j])
                    {
                        Lc[k++] = La[i++];
                    }
                    else
                    {
                        Lc[k++] = Lb[j++];
                    }
                }
    
                //a表中还有数据元素
                while (i <= La.Length - 1)
                {
                    Lc[k++] = La[i++];
                }
                //b表中还有数据
                while (j <= Lb.Length - 1)
                {
                    Lc[k++] = Lb[j++];
                }
                foreach (int c in Lc)
                {
                    Console.Write(c + " ");
                }
    
                Console.ReadKey();
            }

  • 相关阅读:
    面向对象之prototype,__proto__
    Screen对象
    location对象
    history对象
    JS计时器
    window对象
    Dom操作html详细
    终端 git log 修改样式
    null 和 NULL 判断
    textfield设置左边距
  • 原文地址:https://www.cnblogs.com/bianlan/p/2714776.html
Copyright © 2011-2022 走看看