user-0 提问: 合并顺序表的问题

回复:
user: user-0
content: 引用 1 楼 自信男孩的回复:#include <stdio.h>  #define MAXSIZE 100           /* 顺序表的最大长度 */  typedef int ElemType;         /*ElemType 为顺序表元素的类型 */ typedef struct{     ElemType data[MAXSIZE];     int length;              /* 顺序表的实际长度 */ }SqList;   void Creat_SqList(SqList *L,int n) {     int i;     L->length=n;     i=0;     printf("\ninput %d data : ", n);     while(i<n){         scanf("%d",&L->data[i]);         i++;     } }  void Print_SqList(SqList *L) {     int i,n;     n=L->length;     i=0;     printf("\noutput %d data : ",n);     while(i<n)     {         printf("%d ", L->data[i]);         i++;     }     printf("\n"); }  //合并函数的定义  //merge_Seq (SeqList *LA, SeqList *LB, SeqList *LC) void merge_Seq (SqList *LA, SqList *LB, SqList *LC) {     int i,j,k;     i=0,j=0,k=0;       while(i<LA->length&&j<LB->length)         //if(LA->ElemType data[i]<LB->ElemType data[j])         if(LA->data[i] < LB->data[j])         {             //LC->ElemType data[k]=LA->ElemType data[i];             LC->data[k] = LA->data[i];             i++;             k++;         }         else         {             //LC->ElemType data[k] = LB->ElemType data[j];             LC->data[k] = LB->data[j];             j++;             k++;         }      while(i < LA->length)     {         //LC->ElemType data[k]=LA->ElemType data[i];         LC->data[k] = LA->data[i];         i++;         k++;     }       //while(j<LB->last)     while(j<LB->length)     {         //LC->ElemType data[k]=LB->ElemType data[j];         LC->data[k] = LB->data[j];         j++;         k++;     }     //LC->length = LA->length+LB->length+1;     LC->length = LA->length+LB->length; }    //main() int main(void) {     SqList LA,LB,LC;     int n;     printf("\n input1: ");     scanf("%d", &n);     Creat_SqList(&LA,n);      //开始进行第二个数组的输入     n=0;     printf("\n input2: ");     scanf("%d",&n);     Creat_SqList(&LB,n);//输入完毕      Print_SqList(&LA);     Print_SqList(&LB);      merge_Seq(&LA, &LB, &LC);     Print_SqList(&LC); }   供参考～ (⊙o⊙)哇谢谢啦😘

user: user-1
content: #include <stdio.h>  #define MAXSIZE 100           /* 顺序表的最大长度 */  typedef int ElemType;         /*ElemType 为顺序表元素的类型 */ typedef struct{     ElemType data[MAXSIZE];     int length;              /* 顺序表的实际长度 */ }SqList;   void Creat_SqList(SqList *L,int n) {     int i;     L->length=n;     i=0;     printf("\ninput %d data : ", n);     while(i<n){         scanf("%d",&L->data[i]);         i++;     } }  void Print_SqList(SqList *L) {     int i,n;     n=L->length;     i=0;     printf("\noutput %d data : ",n);     while(i<n)     {         printf("%d ", L->data[i]);         i++;     }     printf("\n"); }  //合并函数的定义  //merge_Seq (SeqList *LA, SeqList *LB, SeqList *LC) void merge_Seq (SqList *LA, SqList *LB, SqList *LC) {     int i,j,k;     i=0,j=0,k=0;       while(i<LA->length&&j<LB->length)         //if(LA->ElemType data[i]<LB->ElemType data[j])         if(LA->data[i] < LB->data[j])         {             //LC->ElemType data[k]=LA->ElemType data[i];             LC->data[k] = LA->data[i];             i++;             k++;         }         else         {             //LC->ElemType data[k] = LB->ElemType data[j];             LC->data[k] = LB->data[j];             j++;             k++;         }      while(i < LA->length)     {         //LC->ElemType data[k]=LA->ElemType data[i];         LC->data[k] = LA->data[i];         i++;         k++;     }       //while(j<LB->last)     while(j<LB->length)     {         //LC->ElemType data[k]=LB->ElemType data[j];         LC->data[k] = LB->data[j];         j++;         k++;     }     //LC->length = LA->length+LB->length+1;     LC->length = LA->length+LB->length; }    //main() int main(void) {     SqList LA,LB,LC;     int n;     printf("\n input1: ");     scanf("%d", &n);     Creat_SqList(&LA,n);      //开始进行第二个数组的输入     n=0;     printf("\n input2: ");     scanf("%d",&n);     Creat_SqList(&LB,n);//输入完毕      Print_SqList(&LA);     Print_SqList(&LB);      merge_Seq(&LA, &LB, &LC);     Print_SqList(&LC); }   供参考～