diff --git a/DataStructures/Linked Lists/Merge two Sorted Linked Lists/Solution.cpp b/DataStructures/Linked Lists/Merge two Sorted Linked Lists/Solution.cpp new file mode 100644 index 0000000..dbf9038 --- /dev/null +++ b/DataStructures/Linked Lists/Merge two Sorted Linked Lists/Solution.cpp @@ -0,0 +1,36 @@ + + +// Complete the mergeLists function below. + +/* + * For your reference: + * + * SinglyLinkedListNode { + * int data; + * SinglyLinkedListNode* next; + * }; + * + */ +SinglyLinkedListNode* mergeLists(SinglyLinkedListNode* head1, SinglyLinkedListNode* head2) { +SinglyLinkedListNode* temp; + +if(head1==NULL&&head2==NULL){ + return NULL; + +} + +if(head1==NULL) return head2; +if(head2==NULL) return head1; + +if(head1->datadata){ + head1->next=mergeLists(head1->next,head2); + return head1; +} + +else{ + head2->next=mergeLists(head2->next,head1); + return head2; +} + +} +