Home > Back-end >  Singly linked lists and structure to create a directory management, in which mistakes don't kno
Singly linked lists and structure to create a directory management, in which mistakes don't kno

Time:09-23

#include
#include
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) -- -- -- -- -- -- -- wrong place error: new types may not be defined in a return type
{
Node * p=head;
Node * s=new node;
Strcpy (s - & gt; The name, name);
Strcpy (s - & gt; Tel, tel);
Strcpy (s - & gt; Addr, addr);
S - & gt; Next=p - & gt; Next;
P - & gt; Next=s;
return p;
}
Void the Delete (node * head, char * Name)
{
The node * p=head - & gt; Next;
Node * q;
While (p!=NULL& & STRCMP (p - & gt; The name, the name)!=0)
{
Q=p;
P=p - & gt; Next;
}
If (p==NULL)
Cout<& lt;" This person does not exist!" ;
The else {
Q - & gt; Next=p - & gt; Next;
The delete p;
}
}
Void search (node * head, char * Name)
{
The node * p=head - & gt; Next;
Node * q;
While (p!=NULL& & STRCMP (p - & gt; The name, the name)!=0)
{
Q=p;
P=p - & gt; Next;
}
If (p==NULL)
Cout<& lt;" This person does not exist!" ;
The else {
Cout<& lt; P - & gt; Tel<& lt; "' & lt; & lt; P - & gt; Addr.
}
Int main ()
{
The head node *, * p;
The head=new node;
The head - & gt; Next=NULL;
Int the select;
Char Name [20].
Char Tel [11].
Char Addr [30].
Head={{" zhang ", "12345678900", "hisense 1"}, {" bill ", "13567892086", "chongqing"}, {" detective ", "18875146148", "shantou"}};
While (select!=0)
{
Cout<& lt;" Please enter you need to perform functions: 1 -- add, 2 -- delete, 3 - display, 4 -- search, 5 - end: \ n ";
cin> The select;
The switch (select)
{
Case 1:
Cout<& lt;" Please enter your name, phone number, address: \ n ";
cin> Name> Tel> Addr.
Insert (head, Name, Tel, Addr);
break;
Case 2:
Cout<& lt;" Please enter to delete the names of people: \ n ";
cin> The Name;
Delete (head, Name);
break;
Case 3:
P=the head - & gt; Next;
Cout<& lt;" Contact "& lt; & lt; '\ t' & lt; & lt;" Telephone & lt;" & lt; '\ t' & lt; & lt;" Address "& lt; , '\ n';
While (p!=NULL)
{
Cout<& lt; P - & gt; Name<& lt; '\ t' & lt; & lt; P - & gt; Tel<& lt; '\ t' & lt; & lt; P - & gt; Addr<& lt; '\ n';
P=p - & gt; Next;
}
Case 4:
Cout<& lt;" Please input to find the names of people: \ n ";
cin> The Name;
Search (head, Name);
Case 5:
Cout<& lt;" The end! \n";
break;
}
}
return 0;
}

CodePudding user response:

Void insert (node * head, char * Name, char * Tel, char * Addr)
Void functions cannot be:
return p;

CodePudding user response:

Void functions without a return value of function,