主题:为什么出错了!?应该没错的啊
#define MAX 15
#define ERROR 0
#define OK 1
#include<stdio.h>
#include"stdlib.h"
typedef struct
{
int a[MAX];
int last;
}SeqList;
void getchange(SeqList *LA,SeqList *LB,SeqList *LC)//*非递减有序排列
{
int i,j,k;
i=0;j=0;k=0;
while(i<=LA->last&&j<=LB->last)
if(LA->a[i]<=LB->a[j])
{
LC->a[k]=LA->a[i];
i++;k++;
}
else
{
LC->a[k]=LB->a[j];
j++;k++;
}
while(i<=LA->last)//*当上面的循环结束时,LB已经全部输入到LC了
{
LC->a[k]=LA->a[i];
i++;k++;
}
while(j<=LB->last)//*同上
{
LC->a[k]=LB->a[j];
j++;k++;
}
LC->last=LA->last+LB->last+1;
}
void main()
{
SeqList *LA;
SeqList *LB;
SeqList *LC;
int i,j,k;
LA=(SeqList *)malloc(sizeof(SeqList));
LB=(SeqList *)malloc(sizeof(SeqList));
LC=(SeqList *)malloc(sizeof(SeqList));
printf("输入原有的顺序表LA,LB\n");
printf("顺序表LA的长度");
scanf("%d",&(LA->last));
for(i=0;i<LA->last;i++)
scanf("%d",&LA->a[i]);
printf("顺序表LB的长度");
scanf("%d",&(LB->last));
for(j=0;j<LB->last;j++)
scanf("%d",&LB->a[i]);
getchange(LA,LB,LC);
for(k=0;k<LC->last;k++)
printf("%d ",LC->a[k]);
free(LA);
free(LB);
free(LC);
}
题目是:
有两个顺序表LA,LB,其元素为非递减有序排列,编写一个算法,将它们合并成一个顺序表LC
要求LC也是非递减有序排列!LA=(2,2,3),LB=(1,3,3,4)
则求得的LC应该是(1,2,2,3,3,3,4)
#define ERROR 0
#define OK 1
#include<stdio.h>
#include"stdlib.h"
typedef struct
{
int a[MAX];
int last;
}SeqList;
void getchange(SeqList *LA,SeqList *LB,SeqList *LC)//*非递减有序排列
{
int i,j,k;
i=0;j=0;k=0;
while(i<=LA->last&&j<=LB->last)
if(LA->a[i]<=LB->a[j])
{
LC->a[k]=LA->a[i];
i++;k++;
}
else
{
LC->a[k]=LB->a[j];
j++;k++;
}
while(i<=LA->last)//*当上面的循环结束时,LB已经全部输入到LC了
{
LC->a[k]=LA->a[i];
i++;k++;
}
while(j<=LB->last)//*同上
{
LC->a[k]=LB->a[j];
j++;k++;
}
LC->last=LA->last+LB->last+1;
}
void main()
{
SeqList *LA;
SeqList *LB;
SeqList *LC;
int i,j,k;
LA=(SeqList *)malloc(sizeof(SeqList));
LB=(SeqList *)malloc(sizeof(SeqList));
LC=(SeqList *)malloc(sizeof(SeqList));
printf("输入原有的顺序表LA,LB\n");
printf("顺序表LA的长度");
scanf("%d",&(LA->last));
for(i=0;i<LA->last;i++)
scanf("%d",&LA->a[i]);
printf("顺序表LB的长度");
scanf("%d",&(LB->last));
for(j=0;j<LB->last;j++)
scanf("%d",&LB->a[i]);
getchange(LA,LB,LC);
for(k=0;k<LC->last;k++)
printf("%d ",LC->a[k]);
free(LA);
free(LB);
free(LC);
}
题目是:
有两个顺序表LA,LB,其元素为非递减有序排列,编写一个算法,将它们合并成一个顺序表LC
要求LC也是非递减有序排列!LA=(2,2,3),LB=(1,3,3,4)
则求得的LC应该是(1,2,2,3,3,3,4)