anthogenol100粒怎么吃:C++ 链表问题

来源:百度文库 编辑:神马品牌网 时间:2024/05/09 17:50:05
struct node
{
int info;
struct node* link;
}*h1,*p,*q,*r,*h2;//q在这里定义了
.
.
.

void print(node *list)
{
int j(0);//j为计数器
q=list;
while(q)//遍历连表
{
q=q->link;
printf("%d",q->info);//这里怎么错了?
j++;
j%4?printf("\t"):printf("\n");
}
}
还是不行
打印出来是这样的
842150451 -572662307 Press any key to continue

void print(node *list)
{
int j(0);//j为计数器
q=list;
while(q)//遍历连表
{
printf("%d",q->info);//按你的方法,如果q是空也不会跳出循环的
q=q->link;
j++;
j%4?printf("\t"):printf("\n");
}
}

q=list;
应该改成:
q=new(node);
得分配空间才能操作啊。