What's the problem in the code

unable to understand the problem its compiling and printing correctly but not submitting.

#include
#include
#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);

}

node* take_input(int n){
node* head = NULL;
int d;
for (int i = 0; i < n; i++) {
cin>>d;
insertattail(head , d);
}
return head;
}

node* merge(nodea , nodeb){
// base case
if(a == NULL){
return b;
}
if(b == NULL){
return a;
}

// recursive case
node*c;
if(a->data < b->data){
	c = a;
	c->next = merge(a->next , b);
}

else{
	c = b;
	c->next = merge(a , b->next);
}
return c;

}

void print(node*head){
while(head!=NULL){
cout<data<<" ";
head=head->next;
}
cout<<endl;
}

int main() {
int t;
long long int n1,n2;
cin>>t;
cin>>n1;
node* a = take_input(n1);

cin>>n2;
node* b = take_input(n2);

node* c = merge(a , b);
print(c);
return 0;

}

hi @utkarsh.gupta0311 code is correct, just use t in while loop for no of test cases u r not doing that

ohhhhhhhhhhhhhh :sob::sob::sob::sob::sob:

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.

1 Like