就是两个顺序表合并的问题 不知道代码哪出了问题 求指教
#include <stdio.h>
#include <malloc.h>
#include <stdlib.h>
#define Maxsize 50
typedef struct
{
int data[Maxsize];
int length;
}Sqlist;
void ListInsert(Sqlist *l,int i,int e)
{
int j;
if(i<1||i>l->length+1)
exit(-1);
if(l->length>=Maxsize)
exit(-1);
for(j=l->length;j>=i;j--)
l->data[j]=l->data[j-1];
l->data[i-1]=e;
l->length++;
}
void dislist(Sqlist *l)
{
int i;
for(i=0;i<l->length;i++)
printf("%d ",l->data[i]);
printf("\n");
}
void exchange(Sqlist *a,Sqlist *b,Sqlist *c)
{
int i=0,j=0,k=0;
while((i<a->length)&&(j<b->length))
{
if(a->data[i]<b->data[j])
c->data[k++]=a->data[i++];
else if(a->data[i]>b->data[j])
c->data[k++]=b->data[j++];
}
while(i<a->length)
c->data[k++]=a->data[i++];
while(j<b->length)
c->data[k++]=b->data[j++];
c->length=k;
}
int main()
{
Sqlist *a,*b,*c;
a=(Sqlist*)malloc(sizeof(Sqlist));
a->length=0;
b=(Sqlist*)malloc(sizeof(Sqlist));
b->length=0;
c=(Sqlist*)malloc(sizeof(Sqlist));
c->length=0;
ListInsert(a,1,2);
ListInsert(a,2,3);
ListInsert(a,3,4);
ListInsert(a,4,55);
ListInsert(a,5,123);
ListInsert(b,1,6);
ListInsert(b,2,34);
ListInsert(b,3,56);
ListInsert(b,4,67);
ListInsert(b,5,123);
ListInsert(b,6,234);
ListInsert(b,7,1234);
exchange(a,b,c);
printf("顺序表A:");
dislist(a);
printf("顺序表B:");
dislist(b);
printf("顺序表C: ");
dislist(c);
return 0;
}