La_Lb_Lc
2012-10-08 09:44
183 查看
有数据类型为整型的顺序表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(); }
相关文章推荐
- 分解链表,la表中存放字母,lb中存放数字,lc中存放其它字符
- 将la,lb链表合并成lc。
- 实现La和Lb的交集、并集、差集,并把结果存入Lc中(数据结构)
- 求出递增链表La、Lb的差集Lc,并同样以递增的方式存储
- 已知两个链表 la和 lb,其元素值递增排序。编程将la和lb合并成一个递减有序(相同值元素只保留一个)的链表lc。(北方名校经典试题) 本题选做
- 把元素递增的线性表La和Lb合并为Lc,且Lc的中的元素递减排列,使用原空间
- 用顺序表求lc=la-lb
- 已知头指针分别为la和lb的有序单链表,其数据元素都是按值非递减排列。现要归并la和lb得到单链表lc,使得lc中的元素按值非递减排列。
- 线性链表之将单调递增的la和lb中的数据元素按值递增,将la和lb合并为新的线性表lc,使lc中的元素仍然单调递增
- 线性表LA和LB非递减有序排列,将LA,LB进行归并为新的线性表LC,要求LC中的数据元素扔非递减有序列排列
- 重学数据结构 将Lb中纯在但不在La中的数据元素插入到La中
- void difference(node** LA , node* LB)
- 2.16-从la中删除从i开始len个元素后,把删除的元素放到lb中的j位之前
- 数据结构5:线性表中把属于la中而不属于lb中的元素放到la中
- 判断集合La是否是集合Lb的子集
- 删除Lb重复的数,用La输出(顺序表)
- locale的设定及其LANG、LC_ALL、LA…
- 单链表应用——La∪Lb或La∩Lb
- 数据结构之表中在Lb中但不在La中的元素插入到La中
- 从la中删除字第i个元素起共len个元素后,将他们插入到表lb中第j个元素之前