题解 | #有序序列合并#
有序序列合并
http://www.nowcoder.com/practice/a9e943b0dab142759807d0cfb6863897
#include<stdio.h>
void sort(int a[],int L);
int main()
{
int n, m;
int arr[2000] = { 0 };//不妨存入1个数组 变成排序
scanf("%d%d", &n, &m);
int i;
for (i = 0; i < n; i++)
{
scanf("%d", &arr[i]);
}
for (i = n; i <n+m ; i++) {
scanf("%d",& arr[i]);
}
int M = m + n;
sort(arr, M);//排序
for (i = 0; i < M; i++) {
printf("%d ", arr[i]);
}
return 0;
}
void sort(int a[], int L)
{
int i = 0,c;
for (i = 1; i < L; i++)
{
for (c = 0; c < L - i; c++)
{
if (a[c] > a[c + 1])
{
int n = a[c + 1];
a[c + 1] = a[c];
a[c] = n;
}
}
}
}