码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2014-06-20 16:13:08      阅读:143      评论:0      收藏:0      [点我收藏+]

标签:style   class   blog   code   http   tar   

bubuko.com,布布扣
 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

 

将两个数组A和B合并为一个有序的C数组,布布扣,bubuko.com

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

标签:style   class   blog   code   http   tar   

原文地址:http://www.cnblogs.com/sxmcACM/p/3796741.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!