Nothing is being printed

#include
using namespace std;

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

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

};
void insertAtTail(node *head, int data){
if(head == NULL){
head = new node(data);
return;
}
node *tail = head;
while(tail -> next != NULL){
tail = tail -> next;
}
tail -> next = new node(data);
return;
}

void print(node *head){
while(head != NULL){
cout << head->data << " ";
head = head->next;
}
}
node *merge(node head_1, nodehead_2){
if(head_1 == NULL){
return head_2;
}
if(head_2 == NULL){
return head_1;
}
//recursive case
node *ans;
if(head_1 -> data > head_2 -> data){
ans = head_2;
merge(head_1, head_2 ->next);
}
else{
ans = head_1;
merge(head_1 -> next, head_2);
}
return ans;
}
int main(){
node *head_1 = NULL;
node *head_2 = NULL;

int t;
cin >> t;
while(t>0){
    int n1;
    cin >> n1;
    while(n1 > 0){
        int d;
        cin >> d;
        insertAtTail(head_1, d);
        n1--;
    }

    int n2;
    cin >> n2;
    while(n2 > 0){
        int d;
        cin >> d;
        insertAtTail(head_2, d);
        n2--;
    }

    node *head = merge(head_1, head_2);
    print(head);
    cout << endl;
    print(head_1);
    t--;
}
return 0;

}

hi @vedantmendiratta_2b986865346635fc, please share the code in ide.codingblocks.com big coed are not readable here

hi @vedantmendiratta_2b986865346635fc,
updated and corrected code https://ide.codingblocks.com/s/663826

1 Like

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.