将两个数组A和B合并为一个有序的C数组

 1 # include<iostream>
 2 # include<cstdio>
 3 # include<algorithm>
 4 using namespace std;
 5 void Sort(int a[],int b[],int c[],int n,int m)
 6 {
 7     int A=0, B=0, C=0;
 8     while(A<n && B<m)
 9     {
10         if(a[A] <= b[B])
11             c[C++] = a[A++];
12         else
13             c[C++] = b[B++];
14     }
15     while(A<n)
16         c[C++] = a[A++];
17     while(B<m)
18         c[C++] = b[B++];
19     for(int x = 0; x < n+m; x++)
20     {
21         cout<<c[x]<<" ";
22     }
23 }
24 int main()
25 {
26     int a[1000];
27     int b[1000];
28     int c[2000];
29     int n,m;
30     cin>>n>>m;
31 
32     for(int i = 0; i < n; i++)
33     {
34         cin>>a[i];
35     }
36     sort(a,a+n);
37     for(int j = 0; j < m; j++)
38     {
39         cin>>b[j];
40     }
41     sort(b,b+m);
42     Sort(a,b,c,n,m);
43     return 0;
44 }
View Code

 

转载于:https://www.cnblogs.com/sxmcACM/p/3796741.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值