void insert(node *head,int i,int x)
{
node *p=head->next,*q;
int k=0;
if(i<1)
cout<<"不存在第"<<i<<"個位置"<<endl;
else
{
while(p!=NULL&&k<i)
{
node *q=p->next;——————除錯程序中錯誤的地方,但是不知道怎么改。書上的代碼就是這樣的,可是換到這里就不行了,C-free5.0
p=q;
k++;
}
if(p=NULL)
cout<<"超出鏈表最大可插入位置!"<<endl;
else
{
node *q=new node;
q->data=https://bbs.csdn.net/topics/x;
q->next=p->next;
p->next=q;
}
}
}
uj5u.com熱心網友回復:
第三行 node *p=head->next,*q;node *q=p->next;——————除錯程序中錯誤的地方,
定義了2個*q,會不會這個原因?
uj5u.com熱心網友回復:
我把q去掉之后還是不行。轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/69121.html
標籤:基礎類
上一篇:一本通1166 求f(x,n)
