用链表 死循环

来源:百度知道 编辑:UC知道 时间:2024/05/17 06:00:37
下面这个程序运行的时候问什么会出现死循环?求各位高手帮忙看一下。万分感谢!!
#include<iostream>
using namespace std;
struct node
{
int data;
struct node *next;
};

void select(node *list1)
{
node *p1;
p1=new node;
p1=NULL;
p1=list1->next;
while(p1)
{
cout<<p1->data<<' ';
p1=p1->next;
}
}
int main()
{
node *list,*list0,*list1,*p,*q;
list=new node;
list0=new node;
list1=new node;
p=new node;
list->next=NULL;
list0->next=NULL;
list1->next=NULL;
int a;
cin>>a;
while(a!=0)
{
q=new node;
q->data=a;
q->next=list->next;
p=list;
q->next=p->next;
p->next=q;
p=p->next;
cin>>a;
}
p=list->next;
while(p!=NULL)
{
if(p->data%2==0)
{
list->next=p->next;

main函数里面的东西太多了,弄少点,别放一些控制语句 比如while,for 之类的,很不方便调试。

该了之后自己调试一下,看看问题出在哪,F10是调试,F11是进入指定函数。

一般这些问题自己解决比找人帮好,免得以后犯同样的错。