https://ide.codingblocks.com/s/415094 , Why My code is not Running?
EVEN ODD LINKEDLIST
Try to do it like this,
Or a simple approach will be , make a main linked list. Whenever you encounter a odd element put it in a odd linked list . Whenever you encounter an even element put it in an even linked list
Now put Even,tail = odd,head
and print even,head
you will get required answer.
Hanji Hanji bhaiya samjh gya , thank you ji … abhi kr rha hu koi dikkat hui to btata hu apko
Ha koi issue ho toh bta dena.
thik hai bhaiya kar rha hu 3 test case chal gye ek ni chal rha …ek baar dekhte rehna collaborative mode mai
Check for this test case
5
2 1 7 9 0
bhaiya iska output , 1 7 9 0 2 aa rha , sahi to hai?
1 7 9 2 0 anna chhiye.
dekhna bhaiya ab kya dikkat hai?
bhaiya ek test case ni chal rha ek baar check kr lo
Updated code share krdo ek brri.
Check for this test case
3
1 1 2
2 is not printed. Rest everything seems correct.
yeh toh bhot he jyda complex bna diya, first try to do it with brute force.
L1(for odd linked list)
L2(for even linked list)
Now suppose you get input:
1 2 2 1 8 5 6
- now 1 comes insert at back of L1{1}
- now 2 comes insert at back of L2{2}
- now 2 comes insert at back of L2{2,2}
- now 1 comes insert at back of L1{1,1}
- now 8 comes insert at back of L2{2,2,8}
- now 5 comes insert at back of L1{1,1,5}
- now 6 comes insert at back of L2{2,2,8,6}
Now print (L1,tail)->(L2,head) = {1,1,5,2,2,8,6}
Simple, This is what we want
First try doing this with 2 simple linked list. Then will help you to optimize your approach.
Follow this for better understanding , it’s the most optimized approach i know
Okay , bhaiya krta hu . . . .
Agar is code mai issue ayye toh puchlena.
ab ye jo dusri appproach hai ye smjhado