合并

/* Note:Your choice is C IDE */
#include "stdio.h"
#define N 10
struct shuzhu
{
    int a[N];
    int n;
};
void main()
{
    struct shuzhu a={{1,1,1,1,1},5};
    struct shuzhu b={{2,3,4,5},4};
    struct shuzhu c;
    int i=0,x=0,y=0;
    c.n=0;
    while(x<a.n && y<b.n)
    {
        if(a.a[x]<=b.a[y])
        {
            c.a[i]=a.a[x];
            i++;
            x++;
            c.n++;
        }
        else
        {
            c.a[i]=b.a[y];
            i++;
            y++;
            c.n++;
        }
        
    }
    while(x<a.n)
    {
        c.a[i]=a.a[x];
        i++;
        x++;
        c.n++;
    }
    while(y<b.n)
    {
        c.a[i]=b.a[y];
        i++;
        y++;
        c.n++;
    }
    for(i=0;i<c.n;i++)
    {
        printf("%d\t",c.a[i]);
    }
    
}

猜你喜欢

转载自blog.csdn.net/ly_959/article/details/79037432
今日推荐