code is not working.Pls help.I have used the logic I could possibly think but code is showing error.
Code link:
Even-After-Odd.-Linked list
There are many ways to implement the solution. The easiest will be make two linkedlist one with all odd numbers and other with all even numbers and the add odd number linkedlist tail to even number linkedlist head.
ok…but can you suggest the errors in the code i posted…
Please check your code , your code of creating linkedlist is wrong.
First build linkedlist and check by printing it , then try the question.
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.
I have rectified my code but it is giving segmentation fault(core dumped).
Pls help.
You are not passing the node by reference, so the pointer head is not being updated in main function.
@GreatCoderboy123
I passed by reference but is showing TLE.
Pls help as I think the logic is correct and the code is compiling successfully but it is giving TLE .
@GreatCoderboy123 hey your code has many mistakes.
First you are calling insert function in for loop in main, then in insert function you are reading the entire list in a while loop, now when you will call the insert again it would not have to read any thing.
In the main function inside for loop you are calling the evenodd function , now that function for every new odd or even value is creating an entirely new linked list, instead of adding them to the existing even odd linked list( you have also created separate the structure for the list which are also not required.)
I would suggest you to go through the content of Linked List and Pointer once again it would help in better understanding of concept.
Here is the code for this problem you can refer this.
If this solves your doubt mark it as resolved.
Can you pls explain the complete logic behind the code.As far as I could understand you have taken a seperate start and end pointer for both even and odd numbers.Then you manipulate their positions according to the current pointer.But could you pls explain what happens to their positions.
Ok…I understand it now.No need.Thanks for the help.