merge nhiho rtha
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Merge nhi ho rha hai;;;;;;;;;;;;;;;;;;;;;;
#include using namespace std; class node { public: int data; node *next; node(int d){ data=d; next=NULL; } }; void print(node *head) { while(head!=NULL) { cout<data<<"->"; head=head->next; } } node *merge(node a,nodeb) { if(a==NULL) { return b; } if(b==NULL) { return a; } node *c; if(a->datadata) { c=a; c->next=merge(a->next,b); } else { c=b; c->next=merge(a,b->next); } return c; } void insertAtHead(node *&head,int d) { if(head==NULL) { head=new node(d); return; } else { node *n=new node(d); n->next=head; head=n; } } node *take_input() { int d; cin>>d; node *head=NULL; while(d!=-1) { insertAtHead(head,d); cin>>d; } return head; } int main() { node *head=take_input(); node *head2=take_input(); print(head); cout<<endl; print(head2); node *x=merge(head,head2); cout<<endl; //print(x); //while (x!=NULL) //{ //cout<data<<"->"; // x=x->next; //} }
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.