线性表合并
来源:互联网 发布:淘宝买东西非实名认证 编辑:程序博客网 时间:2024/05/21 07:00
#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include<string>
#include<iomanip>
using namespace std;
#define OK 1
#define ERROR 0
#define OVERFLOW -2
typedef int Status;
typedef int ElemType;
#define MAXSIZE 1000
typedef struct{
ElemType *elem;
int length;
}SqList;
Status InitList_Sq(SqList &L){
L.elem=new ElemType[MAXSIZE];
if(!L.elem) exit(OVERFLOW);
L.length=0;
return OK ;
}
Status ListInsert_Sq(SqList &L,int i,ElemType e){
int j;
for(j=L.length-1;j>=i-1;j--)
L.elem[j+1]=L.elem[j];
L.elem[i-1]=e;
++L.length;
return OK;
}
Status GetElem(SqList L,int i)
{
int e;
e=L.elem[i-1];
return e;
}
int main()
{
SqList La,Lb,Lc;
InitList_Sq(La);
InitList_Sq(Lb);
InitList_Sq(Lc);
int i=0,j=0,k=0;
int ai,bj;
char ch;
while((scanf("%d%c",&La.elem[i++],&ch)==2)&&ch!='\n');
while((scanf("%d%c",&Lb.elem[j++],&ch)==2)&&ch!='\n');
La.length=i, Lb.length=j;
i=j=1;
while(i<= La.length&&j<=Lb.length)
{
ai=GetElem(La,i);
bj=GetElem(Lb,j);
if(ai<=bj)
{
ListInsert_Sq(Lc,++k,ai);
++i;
}
if(bj<ai)
{
ListInsert_Sq(Lc,++k,bj);
++j;
}
}
while(i<=La.length)
{
ai=GetElem(La,i++);
ListInsert_Sq(Lc,++k,ai);
}
while(j<=Lb.length)
{
bj=GetElem(Lb,j++);
ListInsert_Sq(Lc,++k,bj);
}
for(i=0;i<k-1;i++)
cout<<Lc.elem[i]<<" ";
cout<<Lc.elem[k-1];
return 0;
}
#include<stdio.h>
#include<stdlib.h>
#include<string>
#include<iomanip>
using namespace std;
#define OK 1
#define ERROR 0
#define OVERFLOW -2
typedef int Status;
typedef int ElemType;
#define MAXSIZE 1000
typedef struct{
ElemType *elem;
int length;
}SqList;
Status InitList_Sq(SqList &L){
L.elem=new ElemType[MAXSIZE];
if(!L.elem) exit(OVERFLOW);
L.length=0;
return OK ;
}
Status ListInsert_Sq(SqList &L,int i,ElemType e){
int j;
for(j=L.length-1;j>=i-1;j--)
L.elem[j+1]=L.elem[j];
L.elem[i-1]=e;
++L.length;
return OK;
}
Status GetElem(SqList L,int i)
{
int e;
e=L.elem[i-1];
return e;
}
int main()
{
SqList La,Lb,Lc;
InitList_Sq(La);
InitList_Sq(Lb);
InitList_Sq(Lc);
int i=0,j=0,k=0;
int ai,bj;
char ch;
while((scanf("%d%c",&La.elem[i++],&ch)==2)&&ch!='\n');
while((scanf("%d%c",&Lb.elem[j++],&ch)==2)&&ch!='\n');
La.length=i, Lb.length=j;
i=j=1;
while(i<= La.length&&j<=Lb.length)
{
ai=GetElem(La,i);
bj=GetElem(Lb,j);
if(ai<=bj)
{
ListInsert_Sq(Lc,++k,ai);
++i;
}
if(bj<ai)
{
ListInsert_Sq(Lc,++k,bj);
++j;
}
}
while(i<=La.length)
{
ai=GetElem(La,i++);
ListInsert_Sq(Lc,++k,ai);
}
while(j<=Lb.length)
{
bj=GetElem(Lb,j++);
ListInsert_Sq(Lc,++k,bj);
}
for(i=0;i<k-1;i++)
cout<<Lc.elem[i]<<" ";
cout<<Lc.elem[k-1];
return 0;
}
阅读全文
0 0
- 合并两个线性表
- 线性表合并
- 合并线性表
- 线性表合并
- 线性链表合并
- 合并两个线性表
- 线性表合并
- 合并两个线性表
- 线性表算法-合并
- 线性表的合并
- 线性表的合并
- 合并线性表
- 线性表合并
- 线性表的合并
- 合并两个线性表
- 线性表合并
- 线性表—线性表的合并
- 合并线性表(MergeList)
- Swift之delegate代理和Block闭包的反向传值
- vb.net教程 0-1 安装 1
- 渐变
- LeetCode-68-Text Justification 细节题
- 【动态规划】动态规划解题的一般思路——以数字三角形为例
- 线性表合并
- iOS 隐藏导航栏最佳实践
- 机器学习深入与强化--数学基础(3)
- 利用Java输出菱形
- 第二周-项目3
- linux环境下nginx_http服务器的配置
- idea最快上传maven项目
- Spring框架_3.5_运行时值注入
- markdown学习过程