试题一(15分)
[函数1.1说明]
设链表结点的类型为
typedef struct elem{ int val;
struct elem *next;
} intNode;
函数 merge(int *a,int *b) 是将两个升序链表 a 和 b 合并成一个升序链表。
[函数1.1]
intNode *merge(intNode *a,intNode *b)
{ intNode *h = a,*p,*q;
while(b)
{ for (p = h; p && p->val<b->val; q = p, p = p->next);
if (p == h) __(1)__; else __(2)__;
q = b; b = b->next; __(3)__;
}
return h;
}
[函数1.2说明]
递归函数 dec(int a[],int n) 判断数组 a[] 的前 n 个元素是否是不递增的。不递增返回 1 ,否则返回 0 。
[函数1.2]
int dec(int a[],int n)
{ if (n <= 1) __(4)__;
if (a[0] < a[1]) return 0;
return __(5)__;
}