数据结构—2207: 实现链表(线性表)
来源:互联网 发布:英制螺丝孔算法 编辑:程序博客网 时间:2024/06/06 08:30
2207: 实现链表(线性表)
Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 276 Solved: 188
[Submit][Status][Web Board]
Description
(线性表)顺序结构线性表LA与LB的结点关键字为整数。LA与LB的元素按非递减有序,线性表空间足够大。试用给出一种高效算法,将LB中元素合到LA中,使新的LA的元素仍保持非递减有序。高效指最大限度的避免移动元素。
Input
输入LA长度m:7
输入数据:3 7 11 15 57 68 99
输入LB长度n:7
输入数据:6 7 8 9 10 23 67
Output
3 6 7 8 9 10 11 15 23 57 67 68 99
Sample Input
74 6 7 9 10 16 2381 2 4 7 8 13 15 44
Sample Output
1 2 4 6 7 8 9 10 13 15 16 23 44
#include <iostream>#include<malloc.h>using namespace std;int a[100],b[100];typedef int ElemType;typedef struct{ ElemType data[100]; int length;}SqList;void InitList(SqList *&L){ L=(SqList *)malloc(sizeof(SqList)); L->length=0;}void CreatList(SqList *&L,ElemType a[],int n){ int i; L=(SqList *)malloc(sizeof(SqList)); for(i=0;i<n;i++) L->data[i]=a[i]; L->length=n;}int UnionList(SqList *LA,SqList *LB,SqList *&LC){ int i=0,j=0,k=0; LC=(SqList *)malloc(sizeof(SqList)); while(i<LA->length&&j<LB->length) { if(LA->data[i]<LB->data[j]) { LC->data[k]=LA->data[i]; i++;k++; } else if(LA->data[i]==LB->data[j]) { LC->data[k]=LA->data[i]; i++;k++;j++; } else { LC->data[k]=LB->data[j]; j++;k++; } } while(i<LA->length) { LC->data[k]=LA->data[i]; i++;k++; } while(j<LB->length) { LC->data[k]=LB->data[j]; j++,k++; } LC->length=k; return 1;}void OutputList(SqList *&L){ int i; for(i=0;i<L->length;i++) cout<<L->data[i]<<' '; cout<<endl;}int main(){ SqList *LA,*LB,*LC; int m,n,i; cin>>m; for(i=0;i<m;i++) cin>>a[i]; cin>>n; for(i=0;i<n;i++) cin>>b[i]; CreatList(LA,a,m); CreatList(LB,b,n); if(UnionList(LA,LB,LC)) OutputList(LC); return 0;}
0 0
- 数据结构—2207: 实现链表(线性表)
- 【数据结构】线性表(链表实现)
- 数据结构——线性表的实现
- 数据结构栈—线性表实现
- 数据结构-线性结构-线性表及其实现
- 数据结构线性表——链表实现
- 数据结构C语言实现——线性链表
- 数据结构实现顺序线性表
- 数据结构_线性表实现
- 数据结构 线性表实现之一
- 数据结构c++实现----线性表
- 数据结构之线性表实现
- 数据结构--线性表顺序实现
- 基础数据结构--线性表实现
- 数据结构 线性表JAVA实现
- 【数据结构】线性表(数组实现)
- 数据结构-Java实现线性表
- 《C++实现数据结构》:线性表
- 归并排序 小结
- 网易云课堂 Linux内核分析(七)
- hihocode——#1497 : Queen Attack
- Mac 10.11.6 Mysql
- 运维笔记40 Linux系统监控之Cacti(Cacti搭建,自动抓取cacti统计图片脚本)
- 数据结构—2207: 实现链表(线性表)
- C语言编程基础-struct和union
- HDP错误汇总
- spring中context:property-placeholder/元素
- FreeCodeCamp学习--Caesars Cipher
- 动态规划法(三)——最长公共子序列
- 数论基础(POJ2407)
- String学习
- 2017.4.8微软笔试题