我编写的C++程序,插入的地方出错,实在找不出来了

来源:百度知道 编辑:UC知道 时间:2024/05/30 20:17:38
#include<iostream>
using namespace std;
struct person
{
person *next;
int number;
int money;
char name[20];
};
person *list()
{
person *head,*rear,*a;
int no;
head=NULL;
cout<<"输入号码"<<endl;
cin>>no;
while(no)
{
a=new person;
a->number=no;
cout<<"输入工资和姓名"<<endl;
cin>>a->money>>a->name;
if(head==NULL)
head=a;
else
rear->next=a;
rear=a;
cout<<"输入号码"<<endl;
cin>>no;
}
if(rear!=NULL)
rear->next=NULL;
return head;
}
person *daozhi(person *p)
{
person *a,*b,*c;
a=p;
if(a==NULL) return NULL;
b=a->next;
a->next=NULL;
c=a;
a=b;
while(a->next!=NULL)
{
b=a->next;
a->next=c;
c=a;

void charu(person *p,int no)
{
person *a,*b;
int no;//再加一条声明,再不行就传地址调用
a=p;
while(a!=NULL)
{
if(a->number==no)//那就是这里有问题,无论什么情况都无法执行该条语句
break;
a=a->next; //这句不要
}
if(a!=NULL)
{
cout<<"找到节点,输入插入的数据"<<endl;
b=a->next;
a->next=new person;
a=a->next;
a->next=b;
cout<<"输入号码"<<endl;
cin>>a->number;
cout<<"输入工资和姓名"<<endl;
cin>>a->money>>a->name;
}
else
cout<<"节点未找到"<<endl;
}