# Hackerrank Merge two sorted linked lists solution

## Problem Statement

This challenge is part of a tutorial track by MyCodeSchool

You’re given the pointer to the head nodes of two sorted linked lists. The data in both lists will be sorted in ascending order. Change the next pointers to obtain a single, merged linked list which also has data in ascending order. Either head pointer given may be null meaning that the corresponding list is empty.

## Source code:

`````` /*
Merge two sorted lists A and B as one linked list
Node is defined as
struct Node
{
int data;
struct Node *next;
}
*/
{
// This is a "method-only" submission.
// You only need to complete this method
Node *curA,*curB;
while(curB !=NULL){
if(cur== NULL){
break;
}else{    if(cur->data > curB->data){
curA = curB;
curB = curB->next;
curA->next = cur;
if(prev == NULL){
}else{
prev->next = curA;
}
prev = cur;
cur = cur->next;
}else{
if(cur->next !=NULL){
prev = cur;
cur = cur->next;
}else{
cur->next = curB;
break;
}
}}
}  ``````