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?
Testcases Failed
#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, 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
keep coding
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

