通讯录 双向链表
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
//node.h
#include
#include
#include
#include
#include
struct data //数据
{
char name[20]; //姓名
char tel[20]; //电话
int age; //年龄
};
class node //节点
{
friend class link; //友远类
private:
data person; //数据
node * next;
node * pre;
public:
void show() //显示数据信息
{
cout<<"姓名:"< cout<<"电话:"< cout<<"年龄:"< } node(char*name0="",char*tel0="",int age0=0) //构造函数{ strcpy(,name0); strcpy(person.tel,tel0); person.age=age0; next=NULL; pre=NULL; } node(node&n) ////拷贝构造 { strcpy(,); strcpy(person.tel,n.person.tel); person.age=n.person.age; } }; class link{ //双向链表 node * head; //头指针 node * rear; //尾指针 node * findbyname(char*name0,node *temp ) //查找姓名返回地址{ temp=head; if(!head) //空链表 { cout<<"通讯录中没有信息"< return NULL; } node * p=head; while(p){ if(strcmp(p->,name0)==0) //已找到 return p; p=p->next; } while(temp){ if(Cmpstr(temp->,name0)) { cout< temp->show(); } temp=temp->next; } //if(temp) // cout<<"查无此人"< return temp; } node * findbyname(char*name0) //查找姓名返回地址 { if(!head) //空链表 { cout<<"通讯录中没有信息"< return NULL; } node * p=head; while(p){ if(strcmp(p->,name0)==0) //已找到 return p; p=p->next; } if(!p) cout<<"查无此人"< return NULL;//未找到 } int length() //返回链表长度 { if(!head) return 0; node*p; int n=1; p=head; if(p->next) { p=p->next; n++; } return n; } node * findbynum(int num) //根据序号查找 { int l=length(); //l为总长 if(!head) //空链表 { cout<<"通讯录中没有信息"< return NULL; } if(num>l) //数据越界 { cout<<"通讯录里没有"< return NULL; } node * p=head; while(--num) p=p->next; return p; //返回指针 } void change(node*p)//修改对应指针信息 { char tel0[20]; int age0,cho; cout<<"请输入新的电话号码"< cin>>tel0; cout<<"请输入新的年龄"< cin>>age0; cout<<"姓名:"< cout<<"原电话号码:"< cout<<"原年龄:"<