class Solution { public: ListNode* Merge(ListNode* pHead1, ListNode* pHead2) {

if(pHead1==NULL&&pHead2!=NULL)
{
    return pHead2;
}
else if(pHead1!=NULL&&pHead2==NULL)
{
    return pHead1;
}
else if(pHead1==NULL&&pHead2==NULL)
{
    return NULL;
}
struct ListNode*s = pHead1;
struct ListNode*r = pHead2;
vector<int>v;

while(s!=NULL||r!=NULL)
{
    if(s!=NULL)
    {
        v.push_back(s->val);
        s = s->next;
    }
    else
    {
        v.push_back(r->val);
        r = r->next;
    }
}
sort(v.begin(),v.end());
struct ListNode*q=(struct ListNode*)malloc(sizeof(struct ListNode));
struct ListNode*p,*temp;
temp = q;
q->next = NULL;
    
for(int i=0;i<v.size();i++)
{
    p = (struct ListNode*)malloc(sizeof(struct ListNode));
    p->val = v[i];
    p->next = NULL;
    q->next = p;
    q = p;
}
return temp->next;

} };