实验

#include<iostream>
#include<stdlib.h>
#include<malloc.h>
using namespace std;
typedef int Status;
typedef int ElemType;

typedef struct{
ElemType*elem;
int length;
int listsize;
}SqList;

Status create(SqList &L)
{
L.length=0;
L.elem=(ElemType*)malloc(100*sizeof(ElemType));
if(!L.elem) exit(-1);
L.listsize=100;
return 1;
}

Status insert(SqList &L,int i,ElemType e)
{
ElemType *p,*q;
q=&(L.elem[i-1]);
for(p=&L.elem[L.length-1];p>=q;p--)
{
*(p+1)=*p;
}
*q=e;
L.length++;
return 1;
}

int main()
{
SqList L1,L2,L3;
int t;
create(L1);
create(L2);

while(scanf("%d ",&t)!='\n')
{

int i=0;
insert(L1,++i,t);
}
while(scanf("%d ",&t)!='\n')
{
int i=0;
insert(L2,++i,t);
}
create(L3);
int i=0,j=0,k=0;
for(;i<L1.length||j<L2.length;)
{
if(i=L1.length)
insert(L3,++k,(ElemType) L2.elem[j++]);
if(j=L2.length)
insert(L3,++k,(ElemType) L1.elem[i++]);
if(L1.elem[i]<L2.elem[j])
insert(L3,++k,(ElemType) L1.elem[i++]);
else
insert(L3,++k,(ElemType) L2.elem[j++]);
}
{
cout<<L3.elem[i]<<" ";
}
return 0;
}

 

posted @ 2024-09-27 17:15  JUVBuffon  阅读(17)  评论(0)    收藏  举报