Testcases Failed

My code failed in testcase 0 and 4. I checked the output over a very large range of numbers but still I am not able to find the error . Can there be a error due to extra spaces?

Hey @Saumya123456789 :grinning: , in order to tell your mistake I first need to see it

#include #include using namespace std; int main() { list l; int size; cin>>size; int d; for(int i = 0;i<size;i++){ cin>>d; l.sort(); if(d%2){ l.push_front(d); } else{ l.push_back(d); } } for(auto it = l.begin();it!=l.end();it++){ cout<<(*it)<<" "; } return 0; }

Hey @Saumya123456789 use ide.codingblocks.com to share your code.

Hey @Saumya123456789, your approach is little bit incorrect as it works fine when your d is odd but fails when d is even. I have dry run your code here


Just do one thing instead of adding even number in front add it in middle of a linked list. I know you can implement it :grinning: keep coding :+1:

But we are required to put the odd numbers before the even.

Sorry @Saumya123456789 my mistake, just imagine odd numbers instead of even numbers and you will find out your mistake