急救啊 ~~~~~~~~
寻找中间节点
void getmid(Node *head)
{
Node *p=head;
Node *q=head;
while(q->next!=NULL)
{
p=p->next;
q=q->next->next;
}
cout<<p->i<<endl;
}
//如果是0~10 11个数 上面那样写可以 但是如果是 0~9 10个数 那样写就会出现 段错误?
//而如果改成while(q) 0~9是可以的 0~10却又是段错误 怎么回事啊 ?????
[解决办法]
- C/C++ code
while(q->next!=NULL){ p=p->next; q=q->next; if( q != NULL ) q=q->next;}
[解决办法]
一个是p不会空
一个是p的下一个不为空