The header file linklistc: # include & lt; String>
#include
using namespace std;
Struct DataType
{
int ID;
Char name [10].
char ch;
Char phone [13].
Char addr [31]. };
Struct Node
{
DataType data;//data domain
Struct Node * next;//pointer field
};
The class LinkList
{
Public:
LinkList () {first=new Node; First - & gt; Next=NULL; }//a no-parameter constructor
LinkList (DataType a [], int n);//a constructor, with n elements of the array initialization a singly linked list
~ LinkList ();//destructors
DataType xingming (char t [10]);//by name to find address book, return structure
DataType dianhua (char s [13]);//by phone to find contacts, return structure
Void Insert (DataType x);//add a message in the address book
Void the Delete (char t [10]);//remove a person's information
Void PrintList ();//traversal
Private:
Node * first;//the head pointer
};
LinkList: : LinkList (DataType a [], int n)//stern interpolation based singly linked lists
{
The first=new Node;
Node * r=first;
for (int i=0; i
Node * s=new Node;//(1) to establish a new node
S - & gt; data=https://bbs.csdn.net/topics/a [I];//(2) will be a [I] writes data domain to the new node
R - & gt; Next=s;//(3) will be added to the list of new nodes
R=s;//(4) to modify the tail pointer
}
R - & gt; Next=NULL;//terminal node pointer field is set to an empty
}
LinkList: : ~ LinkList ()//destructors
{
Node * p=first;//initialization pointer p
While (p)//to release of node
{
The first=p;//the staging to release node
P=p - & gt; Next;//move working pointer
Delete the first;//release node
}
}
DataType LinkList: : xingming (char t [10])//by name lookup
{
The Node * p=first - & gt; Next;//initialization pointer
While (p)
{
If (STRCMP (p - & gt; Data. The name, t)==0)
{return p - & gt; data;
break; }//find elements being examined, return structure
P=p - & gt; Next;
}
If (STRCMP (p - & gt; Data. The name, t)!=0)
{cout<& lt;" No person "& lt;
DataType LinkList: : dianhua (char s [13])//by phone to find
{
The Node * p=first - & gt; Next;//initialization pointer
While (p)
{
If (STRCMP (p - & gt; Data. The phone, s)==0)
{return p - & gt; data;
break; }//find elements being examined, return structure
P=p - & gt; Next;
}
If (STRCMP (p - & gt; Data. The phone, s)!=0)
{cout<& lt;" Without this number "& lt;
Void LinkList: : Insert (DataType x)//add someone's information
{Node * p=first;//initialization pointer
While (p - & gt; Next!=NULL)
{p=p - & gt; Next; }
The Node * s=p - & gt; Next;
S - & gt; data=https://bbs.csdn.net/topics/x;
S - & gt; Next=NULL;
}
Void LinkList: : Delete (char t [10])//Delete someone's information, and return
{
The Node * p=first - & gt; Next;//initialization pointer
While (p)
{
If (STRCMP (p - & gt; Data. The name, t)==0)
{p - & gt; data=https://bbs.csdn.net/topics/p-> next -> data;
Node * q=p - & gt; Next;
P - & gt; Next=q - & gt; Next;
The delete q; }
If (STRCMP (p - & gt; Data. The name, t)!=0)
{cout<& lt;" Without the person information "; }//return error values
}
Void LinkList: : PrintList ()//in order traverse linear list in each data element
{
The Node * p=first - & gt; Next;//initialization pointer
While (p) {
Cout & lt; P=p - & gt; Next;
}
}
The main program:
#include
# include "linklistc. H"
using namespace std;
Void main ()
{Datatype shuju [6]={{1, "Tom", "m", "13433232785", "New York"}, {2, "Mary", "f", "18600557372", "Beijing"},
{3, "Ashley", "m", "13812474136", "working"}, {4, "xiaoming,", "m", "13651184722", "tianjin"},
{5, "House", "m", "18832800098", "Boston"}, {6, "Lihua", "f", "1861238876", "London"}};
Linklist a (shuju, 6);
int b;
Cout<& lt;" Please enter the want to do "& lt;
While (cin> B)
{if (b==1)
{Amy polumbo rintList (); }
If (b==2)
{cout<& lt;" Please enter the name "& lt;
Cin> t;
DataType c=a.x ingming (t);
Cout
{cout<& lt;" Please enter the phone number "& lt;
Cin> s;
C=a. d. ianhua (s);
Cout
{cout<& lt;" Please enter the name "& lt;
A. d. elete (t); }
If (b==5)
{cout<& lt;" Please input in order ID, name, phone number, gender, address & lt;"
Cin> E.I D> E.n ame> E.p hone> The e.c. with our fabrication: h> E.a DDR.
Anderson, nsert (e); }
If (b==6)
{cout<& lt;" Could you tell me who to modify information "& lt;
C=a.x ingming (t);
Cout<& lt;" Please re-enter the information, followed by ID, phone number, gender, address
"Cin> C.I D> C.p hone> Arthur c. h> C.a. DDR. }}
}
? Really a afternoon, and help, if ihave handed over