Remove odd valued nodes from linked list The function remove_odd is to remove odd valued nodes (surprise!!) from the linked list head. The code is very long and cryptic but it seems to work.

Please help me reduce the lines of code and are there any cases that I might have missed.

void rem_odd(struct Node** head)
{
    struct Node* curr=*head;
    struct Node* l_even=NULL; //l_even stores the last even number node address
    while(curr!=NULL&amp;&amp;curr-&gt;data%2!=0)
    {
        *head=curr-&gt;next;
        if(curr-&gt;next==NULL)
            return;
        curr=curr-&gt;next;
    }
    l_even=curr;
    while(curr!=NULL)
    {
        if(curr-&gt;next==NULL)
            return;
        while(curr!=NULL&amp;&amp;curr-&gt;next-&gt;data%2!=0)
        {

            if (curr-&gt;data%2!=0)
            {
                printf("if ");
                if(curr-&gt;next==NULL)
                {
                    l_even-&gt;next=NULL;
                    return;
                }
                curr=curr-&gt;next;
                l_even-&gt;next=curr;
                if(curr-&gt;next==NULL)
                {
                    l_even-&gt;next=NULL;
                    return;
                }
                continue;
            }
            curr=curr-&gt;next;
            if(curr-&gt;data %2!=0 &amp;&amp;curr-&gt;next==NULL)
            {
                l_even-&gt;next=NULL;
                return;
            }
        }
        if(curr-&gt;next==NULL)
        {
            l_even-&gt;next=NULL;
        }
        else
        {
            l_even-&gt;next=curr-&gt;next;
            l_even=curr-&gt;next;
        }
        curr=curr-&gt;next;
    }
}
It seems you can simplify this by quite a lot.
I added explanation of the algorithm inside the code,
that way it might be easier to follow:

void rem_odd(struct Node** head)
{
    struct Node* curr = *head;
    struct Node* l_even;

    // iterate until the first even element, or the end
    while (curr != NULL &amp;&amp; curr-&gt;data % 2 != 0)
    {
        curr = curr-&gt;next;
    }

    // the new head is the first even element, or the end
    *head = curr;

    // if no more elements, we're done here
    if (curr == NULL) {
        return;
    }

    // the last even element is the current element, naturally
    l_even = curr;

    // we know the current element is even, and not null, so moving on
    curr = curr-&gt;next;

    // iterate until the end
    while (curr != NULL)
    {
        // is the current element even?
        if (curr-&gt;data % 2 == 0) {

            // -&gt; yes, it's even, so the last even element should point to it
            l_even-&gt;next = curr;

            // ... and this is the new last-even-element now
            l_even = curr;
        }
        curr = curr-&gt;next;
    }

    // last even might still point to an odd valued element, so NULL it out
    l_even-&gt;next = NULL;
}


Notice that I added spaces around the operators.
For example this is extremely hard to read:


while(curr!=NULL&amp;&amp;curr-&gt;data%2!=0)