|
#include<iostream> |
|
| 10分 |
参考链表的二路合并算法
https://github.com/707wk/Senior-middle-school/blob/master/Filling%20in%20the%20gaps.c |
|
好复杂,链表我太懂得,,而且C我好多都看不懂的‘’
|
|
|
sort函数的参数是地址,你的参数搞错了.
|
|
| 15分 |
像这样才行.
|
|
sort的参数是iterator,在这里应该是地址,比如c,c+m之类,这里a用来做什么的
|
|
| 15分 |
这样可好:
#include<iostream>
#include<algorithm>
#include<cmath>
#include<string>
using namespace std;
int main()
{
int i, j, r;
int m, n;
int a[100], b[100], c[100];
cin >> m;
for (i = 0; i < m; i++) cin >> a[i];
sort(a, a + m);
cin >> n;
for (i = 0; i < n; i++) cin >> b[i];
sort(b, b + n);
i = j = r = 0;
while (i < m && j < n)
{
if (a[i] <= b[j]) c[r++] = a[i++];
else c[r++] = b[j++];
}
while (i < m) c[r++] = a[i++];
while (j < n) c[r++] = b[j++];
for (int i = 0; i < m + n; i++) cout << c[i] << " ";
cout << endl;
return 0;
}
//3
//2 1 5
//4
//23 45 1 25
//1 1 2 5 23 25 45
|
|
懂了,,谢谢
|
|