Friday 25 August 2017

MIDDLE ELEMENT OF LINKED LIST

int getMiddle(struct Node *head)
{
    if(head==NULL)
        return -1;
    struct Node *fp,*sp;
    fp=head;
    sp=head;
    while(fp&&fp->next)
    {
        sp=sp->next;
        fp=fp->next->next;
    }
    return sp->data;
}

No comments:

Post a Comment