#include<stdio.h>
#include<string.h>
using namespace std;
struct node
{
char name[20];
char tel[11];
char addr[30];
struct node *next;
}
void insert(node *head,char *Name,char *Tel,char *Addr)————-——錯誤地方error: new types may not be defined in a return type
{
node *p=head;
node *s=new node;
strcpy(s->name,Name);
strcpy(s->tel,Tel);
strcpy(s->addr,Addr);
s->next=p->next;
p->next=s;
return p;
}
void Delete(node *head,char *Name)
{
node *p=head->next;
node *q;
while(p!=NULL&&strcmp(p->name,Name)!=0)
{
q=p;
p=p->next;
}
if(p==NULL)
cout<<"此人不存在!";
else{
q->next=p->next;
delete p;
}
}
void search(node *head,char *Name)
{
node *p=head->next;
node *q;
while(p!=NULL&&strcmp(p->name,Name)!=0)
{
q=p;
p=p->next;
}
if(p==NULL)
cout<<"此人不存在!";
else{
cout<<p->tel<<' '<<p->addr;
}
int main()
{
node *head,*p;
head=new node;
head->next=NULL;
int select;
char Name[20];
char Tel[11];
char Addr[30];
head={{"張三","12345678900","海信1棟"},{"李四","13567892086","重慶"},{"王五","18875146148","汕頭"}};
while(select!=0)
{
cout<<"請輸入你需要執行的功能:1——添加,2——洗掉。3——顯示,4——查找,5——結束:\n";
cin>>select;
switch(select)
{
case 1:
cout<<"請輸入姓名、電話、地址:\n";
cin>>Name>>Tel>>addr;
Insert(head,Name,Tel,Addr);
break;
case 2:
cout<<"請輸入要洗掉的人的姓名:\n";
cin>>Name;
Delete(head,Name);
break;
case 3:
p=head->next;
cout<<"聯系人"<<'\t'<<"電話"<<'\t'<<"地址" <,'\n';
while(p!=NULL)
{
cout<<p->name<<'\t'<<p->tel<<'\t'<<p->addr<<'\n';
p=p->next;
}
case 4:
cout<<"請輸入要查找的人的姓名:\n";
cin>>Name;
search(head,Name);
case 5:
cout<<"程式結束!\n";
break;
}
}
return 0;
}
uj5u.com熱心網友回復:
void insert(node *head,char *Name,char *Tel,char *Addr)void函式不能:
return p;
uj5u.com熱心網友回復:
void函式表示無回傳值的函式。轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/69124.html
標籤:基礎類
上一篇:vb.net的程式在visual studio上運行沒問題,但是運行生成的exe檔案會死機
下一篇:請大神指點一下我這個程式的問題
