I did iteratively, taking head->next->next every time, and doing this I swapped head and head->next values not the pointers.
mycode for this:
I did iteratively, taking head->next->next every time, and doing this I swapped head and head->next values not the pointers.
mycode for this:
Hey @hemu1999 your code I fine , there just error in output format after
It should be in format 2-> 1->
That means a extra space after arrow.
error still exists! the compilation is successful not the submission!
Here’s my implementation, you can check it
and find your mistake.
But what’s wrong with my implementation, yours is not iterative way of solving, which i’m trying!
one issue with your code is what if i make ,n = 0
deal with this case also
in your print function after while condition add a new line, cout<<endl;
And you will get your answer accepted. See this : https://ide.codingblocks.com/s/357526
Now it’s working for n=0, but submission was not successful!.
Line number 52 print call was just for explanation, you were calling print function 2 times, now remove line 52 print function and submit it.
In the sample output also they have shown the two before and after swapping!
Any ways even line 52 commented! submission is a failure!
Hey , see your logic is correct
So Should I give up! I have wasted an hour on this?
Thank you for your time!
Give up? Bro you got it right, It’s an achievement for me. Usually every one prefer iterative way but you did it using recursion, moreover it’s not your fault cause of output format. You have given your time, output format doesn’t matter . What matter is the logic. For me you worked to hard and i am happy that from now on you will have confidence in you and you will judge questions without doubting on yourself
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.