7-53 两个有序序列的中位数 (25 point(s))
已知有两个等长的非降序序列S1, S2, 设计函数求S1与S2并集的中位数。
输入样例1:
5
1 3 5 7 9
2 3 4 5 6
输出样例1:
4
输入样例2:
6
-100 -10 1 1 1 1
-50 0 2 3 4 5
输出样例2:
1
因为最近在学链表所以先传用链表做的部分,其实这题直接排序然后输出就完事了(代码在链表方法的后面)。
链表方法:
#include <stdio.h>
#include <stdlib.h>
typedef struct _list{
int data;
struct _list *next;
}List;
List * Create(int n);
List * Find(List *s1, List *s2);
void Print(List *s3, int num);
int main() {
List *s1, *s2, *s3;
int num, i = 0;
scanf("%d", &num);
s1 = Create(num);
s2 = Create(num);
s3 = Find(s1, s2)