for the question swap node in pair the test case are not correct as both input and output test case are same . i unlock the test case and find out that both input and output test cases are same due to that i unable to submit my code. although my code output is correct as i show in the image.please do change in the test case
Same test case in both input and output
@sourya7zX corrected your code just print original link list first
dont forget to hit like and mark resolved if cleared
#include #include<bits/stdc++.h> using namespace std; class node { public: int data; node * next; node(int data) { this->data=data; next=NULL; } }; node * create() { node * head=NULL,* tail=NULL; //cout<<“enter the size of the linklist”<<endl; int size; cin>>size; int n=0; while(n<size) { int d; cin>>d; node * temp=new node(d); if(head==NULL) { head=temp; tail=temp; n=n+1; } else { tail->next=temp; tail=tail->next; n=n+1; } } return head; } void print(node * head) { node * temp=head; while(temp!=NULL) { cout<data<<" "; temp=temp->next; } } node * arrange(node * head) { if(head==NULL || head->next==NULL){ return head; } node * temp=arrange(head->next->next); node *temp_=head->next; temp_->next=head; head->next=temp; return temp_; } int main() { node * head; head=create(); node * t=arrange(head); print(t); return 0; }
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.