Why does my code result in error?

I have dry run it with both even and odd length linked lists and its fine… the conditions are also correct but my program stops working when it reaches this part.

please tell why is it not working…

why are u writing so much code to find the mig point of linked list??

it just 3 lines code

  ListNode* middleNode(ListNode* head) {
        ListNode *s = head, *f = head; 
        while(f!= NULL and f->next!= NULL){
            s = s->next;
            f = f->next->next;
            
        }
        return s;
    }

thanks :slight_smile: it works… but what if i want the 2 midpoints for even length linked list?

kabhi pochte h nhi but then u can mantain prev pointer of slow node
then u can get ddata to both nodes

ok thanks again ma’am

1 Like