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;
}
{
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