I TRIED RECURSIVE APPROACH TO THE PROBLEM BUT COULDN’T DO IT! PLEASE HELP
Even after odd linked list problem
Hello mohit. Can you please elaborate your problem? What are you unable to understand in the question i recursive solution
@mohit_99 ok mohit
follow this step to implement this question
make a insert function which basically accept two parameters a head and data
how this insert function work on the given input
before making this function you need a helper function like this
node* oddEven(node* head){
node* oddHead = NULL; // if element is odd add to odd list else add to even list
node* evenHead = NULL;
while(head!=NULL){ // iterating over all elements
if(((head->data)&1)==1){
insertAtHead(oddHead, head->data);
}
else{
insertAtHead(evenHead, head->data);
}
head=head->next;
}
if(oddHead==NULL)
oddHead=evenHead;
else{
node*temp = oddHead;
while(temp->next!=NULL){
temp = temp->next;
}
temp->next = evenHead;
}
return oddHead;
}
hope this will help.
very good solution with explanation
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.
rather than insertAtHead use InsertAtTail for correct output as we want output for
input
1 2 6 4 3
correct output
1 3 2 6 4
…your output is
3 1 4 6 2 which is wrong .