I have made the same program but the recursive method does't work properly

The list isn’t terminating with null.
Please check out what’s the problem.
#include
using namespace std;

// Program to make a linked list with following manipulation options:
// 1. Merging two lists using Mergesort kind of approach.
// 2. Merging two lists using Recursive approach.

class node{
public:
int data;
node* next;

	node(int val){
		data = val;
		next = NULL;
	}

};

class LinkedList{
private:
node* head;

public:
	// constructor
	LinkedList(){
		head = NULL;
	}
		
	// Destructor to delete all the dynamically memory allocated nodes in list.
	~LinkedList(){
		while(head != NULL){
			node* save = head->next;
			delete head;
			head = save;
		}
	}
	
	// Returns the node at Head
	node getHeadNode(){
		return *head;
	}
	
	// Returns head
	node* getHead(){
		return head;
	}
	
	// Prints the list
	void printList(){
		cout<<"Printing list: \n";
		node* temp = head;
		while(temp != NULL){
			cout<<temp->data<<" -> ";
			temp = temp->next;
		}
		cout<<"END\n";
	}
	
	void insertAtHead(int temp){

		node* newNode = new node(temp);				
			if(head==NULL){
				head = newNode;
			} else{
				node* save = head;
				head = newNode;
				newNode->next = save;
			}
	}
	// creates a list by inserting at head 
	void createLinkList(){
		bool flag = true;
		cout<<"Enter integer to be inserted in list ( Enter -1 to terminate list building ) : \n";
		while(flag){
			int temp;
			cin>>temp;
			
			if(temp != -1){
				insertAtHead(temp);
			} else{
				// Terminating list building
				flag = false;
			}
		}
		printList();
	}

};

node* mergeLists(node* h1, node* h2){
node* head=NULL;
node* tail=NULL;

if( (h1->data) <= (h2->data) ){			// Deciding the head
	head = h1;
	tail = h1;
	h1 = h1->next;
} else{
	head = h2;
	tail = h2;
	h2 = h2->next;
}

while(h2 != NULL && h1 != NULL){		//setting links in ascending order of data comparing both lists 
		
	if( (h1->data) <= (h2->data) ){
		tail->next = h1;
		h1 = h1->next;
	} else{
		tail->next = h2;
		h2 = h2->next;
	}
	tail = tail->next;
}

while(h1 != NULL){						// Setting(copying) links into list1 if not reached to null yet
	tail->next = h1;
	h1 = h1->next;
	tail = tail->next;
}

while(h2 != NULL){						// Setting(copying) links into list2 if not reached to null yet
	tail->next = h2;
	h2 = h2->next;
	tail = tail->next;
}

return head;

}

void printUsingHead(node* temp){
while(temp != NULL){
temp = temp->next;
}
cout<<“END”<<endl;
}

node* mergeListsRecursively(node* h1, node* h2){
//
// cout<data<<" "<data<<endl;
// system(“pause”);
//
if(h1 == NULL){
return h2;
} else if(h2 == NULL){
return h1;
}
node* head;

if(h1->data < h2->data){
	head = h1;
	head->next = mergeListsRecursively(h1->next, h2);
} else{
	head = h2;
	head->next = mergeListsRecursively(h1, h2->next);
}

return head;

}

int main(){
LinkedList list1, list2;
list1.createLinkList();
list2.createLinkList();
cout<<“Using mergesort like iterative approach : \n”;
node* mergedListHead = mergeLists(list1.getHead(), list2.getHead());
printUsingHead(mergedListHead);
cout<<“Using recursive approach : \n”;
node* mergedListHead2 = mergeListsRecursively(list1.getHead(), list2.getHead());
printUsingHead(mergedListHead2);
}

@alok.maurya please save your code on ide.codingblocks.com and share the link

sorry for posting code like this.

node *mergelists(node *head1,node *head2)
{
if(head1==NULL)
return head2;
if(head2==NULL)
return head1;

node *newhead;
if(head1->data<head2->data)
{
    newhead = head1;
    newhead->next = mergelists(head1->next,head2);
}
else
{
    newhead = head2;
    newhead->next = mergelists(head1,head2->next);
}
return newhead;

}

This will do the trick.

nevermind, my doubt is resolved

@alok.maurya please mark your doubt as resolved then