13829 - Linked List Mergence   

Description

In addition to Quicksort, merge sort is also a quite significant and classical sorting algorithm. Whereas partition is the most vital step of Quicksort, the most crucial step of merge sort  is to merge two sorted (non-decreasing, typically) sequences into a sorted one.

For instance, if we have two sorted sequence {1, 3, 8}, {2, 9}, then the merged sequence would be {1, 2, 3, 8, 9}.

This is a partial-judged problem. Please implement the following function:

node *merge_linked_list(node *, node *);

Where node is declared as:

typedef struct _node {
int val;
struct _node *next;
}
node;

 

Input

The function would be called with the heads of the two sorted linked list.

It's guaranteed that the sum of the length of the linked lists would not exceed 2000000.

Output

It should return the head of the merged linked list.

Sample Input  Download

Sample Output  Download

Partial Judge Code

13829.c

Partial Judge Header

13829.h

Tags




Discuss