去公司面试的时候,他题的程序题,大神们帮忙看看啊,嘿嘿

有两个升序的整型数组a和b,把a和b的数字放到数组c中,并且保证数组c也是有序的,请写一段代码实现
有一个长度为N的单向链表,写一段代码倒置这个链表。
如 节点1 → 节点2 → 节点3 … → 节点N,变成:
节点1 ← 节点2 ← 节点3 … ← 节点N
允许改变原链表。
求大神们看看,帮小弟解答解答

看来楼主还不太熟悉这些题目的编程思想吧。

1,一个典型的归并排序中的归并动作;

2,用三个指针分别执行上一,当前,下一个,进行逆转即可猛手。

代码:

//1st
void merge(int a[], int b[], int c[], int alen, int blen)
{
 int i = 0, j = 0, k = 0;
 while(i <= alen &悔知笑& j <= blen)
  if(a[i] < b[j])c[k++] = a[i++];
  else c[k++] = b[j++];
 
 while(i <= alen)c[k++] = a[i++];
 while(j <碧含= blen)c[k++] = b[j++];
}
//2nd

Node* reverse(Node* head)
{
 Node *pre = NULL, *cur = head, *next = head->next;
 while(next != NULL)
 {
  cur->next = pre;
  pre = cur;
  cur = next;
  next = next->next;
 }
 return cur;
}