C语言,数据结构,解决一下

题目简述:两列已经按高矮顺序排好队的幼儿园小朋友要过斑马线,交警要求单列通过;编写算法帮助老师实现目标,保持原高矮顺序不变。
相关提示:如果第一列高矮顺序:1,3,4,5,7,9,第二列高矮顺序:2,6,8,则新列应输出:1,2,3,4,5,6,7,8,9。


#include <iostream>
using namespace std;
int main()
{
    int a[10],b[10],c[20];
    int n,m,k=0,i,j=0;
    cin>>n>>m;
    for(i=0;i<n;i++)
        cin>>a[i];
    for(i=0;i<m;i++)
        cin>>a[j];
    i=0;
    while(i<n && j<m)
    {
        if(a[i] <= b[j])
        {
            c[k++] = a[i];
            i++;
        }
        else
        {
            c[k++] = b[j];
            j++;
        }
    }
    if(i<n)
       for(j=i;j<n;j++)
          c[k++] = a[j];
    if(j<m)
          for(i=j;i<m;i++)
                c[k++] - b[i];
    for(i=0;i<k;i++)
        printf("%d ",c[i]);
    return 0;
}
 

#include<stdio.h>
#include<stdlib.h>
struct node
{
int data;
struct node *next;
};
struct node *creat(int n)
{
int i;
struct node *head,*p,tail;
head=(struct node
)malloc(sizeof(struct node));
head->next=NULL;
tail=head;
for(i=0;i<n;i++)
{
p=(struct node*)malloc(sizeof(struct node));
scanf("%d",&p->data);
p->next=NULL;
tail->next=p;
tail=p;
}
return head;
}

struct node *merge(struct node *head1,struct node *head2)

{
struct node *p1,*p2,*tail;
p1=head1->next;
p2=head2->next;
tail=head1;
free(head2);
while(p1&&p2)
{
if(p1->datadata)
{
tail->next=p1;
tail=p1;
p1=p1->next;
}
else
{
tail->next=p2;
tail=p2;
p2=p2->next;
}
}
if(p1)tail->next=p1;
else tail->next=p2;
return head1;
}

int main()

{
int n,m;
struct node *head1,*head2,*p;
scanf("%d",&m);
head1=creat(m);
scanf("%d",&n);
head2=creat(n);
head1=merge(head1,head2);
p=head1->next;
while(p)
{
printf("%d ",p->data);
p=p->next;
}
return 0;
}