* struct ListNode {
 *	int val;
 *	struct ListNode *next;
 * };
 *
 * C语言声明定义全局变量请加上static,防止重复定义
 */

/**
 * 
 * @param pHead1 ListNode类 
 * @param pHead2 ListNode类 
 * @return ListNode类
 */
struct ListNode* Merge(struct ListNode* pHead1, struct ListNode* pHead2 ) {
    // write code here
    if(!pHead1){
        if(!pHead2)
            return NULL;
        return pHead2;
        
    }
    if(!pHead2){
        if(!pHead1)
            return NULL;
        return pHead1;
    }
    int k=0,list[5000];
    while(pHead1){
        list[++k]=pHead1->val;
        pHead1=pHead1->next;
    }
    while(pHead2){
        list[++k]=pHead2->val;
        pHead2=pHead2->next;
    }
    for(int i=1;i<k;i++){
        for(int j=i;j<=k;j++){
            if(list[i]>list[j]){
                int t=list[i];
                list[i]=list[j];
                list[j]=t;
            }
        }
    }
    struct ListNode *head,*l;
    head=(struct ListNode *)malloc(sizeof(struct ListNode *));
    head->val=list[1];
    head->next=NULL;
    l=head;
    for(int i=2;i<=k;i++){
        struct ListNode *r;
        r=(struct ListNode *)malloc(sizeof(struct ListNode *));
        r->val=list[i];
        l->next=r;
        l=r;
        l->next=NULL;
    }
    return head;
}