本文实例为大家分享了C++使用链表存储实现通讯录功能管理的具体代码,供大家参考,具体内容如下
简介
这是第二周老师给的一个小项目要求实现基本通讯录功能,有数据的增删改查,包含插入时间的能力。
代码详情
头文件
- #include <iostream>
- #include <string>
- #include<malloc.h> //system功能调用?
- #include <windows.h> //使用本地系统API获取插入时间?
- #include <sstream>
基本存储结构体
- typedef struct info{
- ?? ?string number;
- ?? ?string date;
- ?? ?string name;
- ?? ?string adress;
- ?? ?string birthday;?
- }A;
- typedef struct LNode{
- ?? ?A data;?
- ? ? struct LNode *next;
- }LNode,*LinkList;
链表数据初始化
用前插法插入数据
- int InitList(LinkList &L){ //初始化链表?
- ?? ?L = new LNode;
- ?? ?L->next = NULL;
- ?? ?return OK;
- }
- int ListInsert(LinkList &L,string name,string adress,string birthday,string date,string number){ //考虑使用数组来赋值?
- ?? ?LinkList p; p= new LNode;
- ?? ?p->data.name = name;
- ?? ?p->data.adress = adress;
- ?? ?p->data.date = date;
- ?? ?p->data.birthday = birthday;
- ?? ?p->data.number = number;
- ?? ?p->next = L->next;
- ?? ?L->next = p;
- ?? ?return OK;
- }?
本地WindowsAPI调用插入时间
- SYSTEMTIME sys;?
- GetLocalTime( &sys );
- string y = doubleToString(sys.wYear);
- string m = doubleToString(sys.wMonth);
- string d = doubleToString(sys.wDay);
- string ymd = y+"-"+m+"-"+d;
因为获取的是一个double值,您得对其时间强制类型转换
- string doubleToString(double num)
- { //强制类型转换 double强制转换为string类型?
- ? ? stringstream ss;
- ? ? string str;
- ? ? ss << num;
- ? ? ss >> str;
- ? ? return str;
- }
数据查询功能
- LinkList SearchElemChar(LinkList L,int i,string e){ //思路,传递参数1,2,3,4,eg 1代表name,再分不同的方法在链表内循环查找操作?
- ?if (i == 1){ //查名字?
- ??? ?while(L!= NULL){
- ??? ??? ?if(L->data.name == e){
- ??? ??? ??? ?return L;?
- ?? ??? ? }else{
- ?? ??? ? L = L->next;
- ?? ??? ? }
- ??? ??? ?}
- ??? ??? ?if(L = NULL){
- ??? ??? ??? ?cout << "未查到数据!"<<endl;
- ?? ??? ? }
- ?}else if(i == 2){//查生日?
- ??? ?while(L!= NULL){
- ??? ??? ?if(L->data.birthday == e){
- ??? ??? ??? ?return L;?
- ?? ??? ? }else{
- ?? ??? ? L = L->next;
- ?? ??? ? }
- ??? ??? ?}
- ??? ??? ?if(L = NULL){
- ??? ??? ?cout <<"未查到数据!"<<endl;
- ?? ??? ? }
- ?}
- ?else if(i == 3){//查地址?
- ??? ?while(L!= NULL){
- ??? ??? ?if(L->data.adress == e){
- ??? ??? ??? ?return L;?
- ?? ??? ? }else{
- ?? ??? ? L = L->next;
- ?? ??? ? }
- ??? ??? ?}
- ??? ??? ?if(L = NULL){
- ??? ??? ?cout <<"未查到数据!"<<endl;
- ?? ??? ? }
- ?}else if(i == 4){//查时间?
- ??? ?while(L!= NULL){
- ??? ??? ?if(L->data.date == e){
- ??? ??? ??? ?return L;?
- ?? ??? ? }else{
- ?? ??? ? L = L->next;
- ?? ??? ? }
- ??? ??? ?}
- ??? ??? ?if(L = NULL){
- ??? ??? ?cout <<"未查到数据!"<<endl;
- ?? ??? ? }
- ?}
- ?else if(i == 5){//查电话?
- ??? ?while(L!= NULL){
- ??? ??? ?if(L->data.number == e){
- ??? ??? ??? ?return L;?
- ?? ??? ? }else{
- ?? ??? ? L = L->next;
- ?? ??? ? }
- ??? ??? ?}
- ??? ??? ?if(L = NULL){
- ??? ??? ?cout <<"未查到数据!"<<endl;
- ?? ??? ? }
- ?}
- ?
- }?
完整案例
- //乐公第二周项目 实现基本通讯录存储结构?
- //基础链表存储数据
- #include <iostream>
- #include <string>
- #include<malloc.h> //system功能调用?
- #include <windows.h> //使用本地系统API获取插入时间?
- #include <sstream>
- #define ERROR 0
- #define OK 1
- using namespace std;
- typedef ?int ElemType; /*定义表元素的类型*/
- //结构体文件
- typedef struct info{
- ?? ?string number;
- ?? ?string date;
- ?? ?string name;
- ?? ?string adress;
- ?? ?string birthday;?
- }A;
- typedef struct LNode{
- ?? ?A data;?
- ? ? struct LNode *next;
- }LNode,*LinkList;
-
- int InitList(LinkList &L){ //初始化链表?
- ?? ?L = new LNode;
- ?? ?L->next = NULL;
- ?? ?return OK;
- }
- int ListInsert(LinkList &L,string name,string adress,string birthday,string date,string number){ //考虑使用数组来赋值?
- ?? ?LinkList p; p= new LNode;
- ?? ?p->data.name = name;
- ?? ?p->data.adress = adress;
- ?? ?p->data.date = date;
- ?? ?p->data.birthday = birthday;
- ?? ?p->data.number = number;
- ?? ?p->next = L->next;
- ?? ?L->next = p;
- ?? ?return OK;
- }?
- //查找元素 (难题需要解决)
- ?
- LinkList SearchElemChar(LinkList L,int i,string e){ //思路,传递参数1,2,3,4,eg 1代表name,再分不同的方法在链表内循环查找操作?
- ?if (i == 1){ //查名字?
- ??? ?while(L!= NULL){
- ??? ??? ?if(L->data.name == e){
- ??? ??? ??? ?return L;?
- ?? ??? ? }else{
- ?? ??? ? L = L->next;
- ?? ??? ? }
- ??? ??? ?}
- ??? ??? ?if(L = NULL){
- ??? ??? ??? ?cout << "未查到数据!"<<endl;
- ?? ??? ? }
- ?}else if(i == 2){//查生日?
- ??? ?while(L!= NULL){
- ??? ??? ?if(L->data.birthday == e){
- ??? ??? ??? ?return L;?
- ?? ??? ? }else{
- ?? ??? ? L = L->next;
- ?? ??? ? }
- ??? ??? ?}
- ??? ??? ?if(L = NULL){
- ??? ??? ?cout <<"未查到数据!"<<endl;
- ?? ??? ? }
- ?}
- ?else if(i == 3){//查地址?
- ??? ?while(L!= NULL){
- ??? ??? ?if(L->data.adress == e){
- ??? ??? ??? ?return L;?
- ?? ??? ? }else{
- ?? ??? ? L = L->next;
- ?? ??? ? }
- ??? ??? ?}
- ??? ??? ?if(L = NULL){
- ??? ??? ?cout <<"未查到数据!"<<endl;
- ?? ??? ? }
- ?}else if(i == 4){//查时间?
- ??? ?while(L!= NULL){
- ??? ??? ?if(L->data.date == e){
- ??? ??? ??? ?return L;?
- ?? ??? ? }else{
- ?? ??? ? L = L->next;
- ?? ??? ? }
- ??? ??? ?}
- ??? ??? ?if(L = NULL){
- ??? ??? ?cout <<"未查到数据!"<<endl;
- ?? ??? ? }
- ?}
- ?else if(i == 5){//查电话?
- ??? ?while(L!= NULL){
- ??? ??? ?if(L->data.number == e){
- ??? ??? ??? ?return L;?
- ?? ??? ? }else{
- ?? ??? ? L = L->next;
- ?? ??? ? }
- ??? ??? ?}
- ??? ??? ?if(L = NULL){
- ??? ??? ?cout <<"未查到数据!"<<endl;
- ?? ??? ? }
- ?}
- ?
- }?
-
- LinkList SearchElemBefore(LinkList L,string e){ //删除结点必须返回前个结点的地址,这里查找前个结点?
- ? ? ?LinkList P;?
- ??? ?while(L!= NULL){
- ??? ??? ?if(L->data.name == e){
- ??? ??? ??? ?return P;?
- ?? ??? ? }else{
- ?? ??? ? P = L;
- ?? ??? ? L = L->next;
- ?? ??? ? }
- ??? ??? ?}
- ??? ??? ?if(L = NULL){
- ??? ??? ??? ?return L;?
- ?? ??? ? }
- }?
- int ShowMenu(){ //主菜单?
- ?? ?int a;
- ?? ?cout<<"------欢迎您使用乐公通讯录系统!------"<< endl;
- ?? ?cout <<"-----请根据功能输入对应的序号--------" <<endl;?
- ?? ?cout <<"-----------1.新建联系人--------------" <<endl;?
- ?? ?cout <<"--------2.查看所有联系人-------------" <<endl;?
- ?? ?cout <<"--------3.修改选定联系人-------------" <<endl;
- ?? ?cout <<"--------4.查询选定联系人-------------" <<endl;
- ?? ?cout <<"--------5.删除选定联系人-------------" <<endl;
- ?? ?cout <<"------------6.退出系统---------------" <<endl;?
- ?? ?cout << "请您输入序号并按回车进入:" ;?
- ?? ?cin >> a;
- ?? ?return a;
- }
-
- string doubleToString(double num)
- { //强制类型转换 double强制转换为string类型?
- ? ? stringstream ss;
- ? ? string str;
- ? ? ss << num;
- ? ? ss >> str;
- ? ? return str;
- }
- void foreachelem(LinkList L){
- ?? ?if(L->next == NULL){
- ?? ??? ?cout<<"通讯录里还没有联系人,快去新建一下吧~"<<endl;?
- ?? ?}else{
- ?? ?while(L->next!=NULL){
- ?? ??? ?L=L->next;
- ?? ??? ?cout<< "联系人姓名:" << L->data.name <<endl;
- ?? ??? ?cout<< "联系人电话:" << L->data.number<<endl;
- ?? ??? ?cout<< "联系人地址:" << L->data.adress <<endl;
- ?? ??? ?cout<< "联系人生日:" << L->data.birthday <<endl;
- ?? ??? ?cout<< "录入时间:" << L->data.date <<endl;
- ?? ?}
- ?? ?cout<< "\n";
- }
- //system("pause");
- }
- int serachsamename(LinkList L,string name){ //查找是否存在姓名相同的联系人?
- ?? ?while(L->next!=NULL){
- ?? ??? ?L=L->next;
- ?? ??? ?if(L->data.name==name)return 0;
- ?? ?}
- ?? ?return 1;
- }?
- int main(){
- ?? ?int i;
- ?? ?LinkList L;
- ?? ?InitList(L);
- ?? ?while(i!=6){
- ?? ??? ?i = ShowMenu();
- ?? ??? ?if(i ==1){
- ?? ??? ??? ?cout << "您选择了:新建联系人" <<endl;?
- ?? ??? ??? ?string number;
- ?? ??? ??? ?string date;
- ?? ? ? ? ? ?string time;
- ?? ? ? ? ? ?string name;
- ?? ? ? ? ? ?string adress;
- ?? ? ? ? ? ?string birthday;?
- ?? ? ? ? ? ?cout << "请输入联系人姓名:";?
- ?? ??? ??? ?cin >> name;
- ? ? ? ? ? ? ?SYSTEMTIME sys;?
- ? ? ? ? ? ? ?GetLocalTime( &sys );
- ? ? ? ? ? ? ?string y = doubleToString(sys.wYear);
- ? ? ? ? ? ? ?string m = doubleToString(sys.wMonth);
- ? ? ? ? ? ? ?string d = doubleToString(sys.wDay);
- ? ? ? ? ? ? ?string ymd = y+"-"+m+"-"+d;
- ? ? ? ? ? ? int repeat = serachsamename(L,name);?
- ? ? ? ? ? ? if(repeat == 0){
- ? ? ? ? ? ? ?? ?cout << "联系人姓名重复,请删除旧联系人或更改姓名!" << endl;?
- ?? ??? ??? ? }else{
- ?? ??? ??? ? ?? ?cout << "请输入联系人电话:";?
- ?? ??? ??? ? ? ?cin >> number;
- ? ? ? ? ? ? if(number.size()!=11){
- ? ? ? ? ? ? ?? ?cout << "手机号输入有误,请大于11位!" << endl;?? ?
- ?? ??? ??? ?}else{
- ?? ??? ??? ??? ?cout << "请输入联系人生日:";?
- ?? ??? ??? ?cin >> birthday;
- ?? ??? ??? ?cout << "请输入联系人地址:";?
- ?? ??? ??? ?cin >> adress;
- ?? ??? ??? ??? ?cout << "联系人于" << ymd;
- ?? ??? ??? ??? ?int ok;
- ?? ??? ??? ?ok = ?ListInsert(L,name,adress,birthday,ymd,number);
- ?? ??? ??? ?if(ok == 1){
- ?? ??? ??? ??? ?cout << "日新建成功!" << endl;?
- ?? ??? ??? ?}else{?
- ?? ??? ??? ?cout << "新建失败!" << endl;
- ?? ??? ??? ?}?
- ?? ??? ??? ?}
- ?? ??? ?}
- ?? ??? ??? ?system("pause");
- ?? ??? ??? ?system("cls");
- ?? ??? ?}else if(i==2){
- ?? ??? ??? ?cout << "您选择了:遍历联系人" <<endl;?
- ?? ??? ??? ?foreachelem(L);
- ?? ??? ??? ?system("pause");
- ?? ??? ??? ?system("cls");
- ?? ??? ??? ?
- ?? ??? ?}else if(i==3){
- ?? ??? ??? ?cout << "您选择了:修改选定联系人" <<endl;?
- ?? ??? ??? ?cout <<"请输入要修改的联系人姓名:" ;
- ?? ??? ??? ?string name;
- ?? ??? ??? ?cin >> name;
- ?? ??? ??? ?LinkList B;
- ?? ??? ??? ?B = SearchElemChar(L,1,name);
- ?? ??? ??? ? if(B){
- ?? ??? ??? ? ?? ?system("cls");
- ?? ??? ??? ? ?? ?cout << "联系人查找成功!姓名:" << B->data.name << endl;?
- ?? ??? ??? ? ?? ?int select;
- ?? ??? ??? ? ?? ?cout <<"---------修改姓名请输入1---------" << endl;
- ?? ??? ??? ??? ?cout <<"---------修改电话请输入2---------" << endl;?
- ?? ??? ??? ??? ?cout <<"---------修改生日请输入3---------" << endl;?
- ?? ??? ??? ??? ?cout <<"---------修改地址请输入4---------" << endl;?
- ?? ??? ??? ? ?? ?cout <<"请根据序号输入对象的选项修改:" ;
- ?? ??? ??? ? ?? ?cin >> select;
- ?? ??? ??? ? ?? ?switch(select){
- ?? ??? ??? ? ?? ??? ?case 1:?
- ?? ??? ??? ? ?? ??? ?{?? ?string name;
- ?? ??? ??? ??? ??? ?cout <<"请输入新姓名:";?
- ?? ??? ??? ??? ??? ?cin >> name;
- ?? ??? ??? ??? ??? ?B->data.name = name;
- ?? ??? ??? ??? ??? ?cout <<"修改完成!" << endl;
- ?? ??? ??? ??? ??? ?break;?
- ?? ??? ??? ??? ??? ? }
- ?? ??? ??? ??? ??? ?case 2: {
- ?? ??? ??? ??? ??? ?string number;
- ?? ??? ??? ??? ??? ?cout <<"请输入新电话:";?
- ?? ??? ??? ??? ??? ?cin >> number;
- ?? ??? ??? ??? ??? ?if(number.size()!=11){
- ? ? ? ? ? ? ?? ? ? ?cout << "手机号输入有误,请大于11位!" << endl;?? ?
- ?? ??? ??? ? ? ? ? ?}else{
- ?? ??? ??? ??? ??? ?B->data.number = number;
- ?? ??? ??? ??? ??? ?cout <<"修改完成!" << endl;
- ?? ??? ??? ??? ??? ?}
- ?? ??? ??? ??? ??? ?break;
- ?? ??? ??? ??? ??? ?}
- ?? ??? ??? ? ?? ??? ?case 3:{
- ?? ??? ??? ? ?? ??? ??? ?string birthday;
- ?? ??? ??? ? ?? ??? ??? ?cout <<"请输入新生日:";?
- ?? ??? ??? ? ?? ??? ??? ?cin >> birthday;
- ?? ??? ??? ? ?? ??? ??? ?B->data.birthday = birthday;
- ?? ??? ??? ??? ??? ? ? ?cout <<"修改完成!" << endl;
- ?? ??? ??? ??? ??? ??? ?break;
- ?? ??? ??? ??? ??? ? }
- ?? ??? ??? ??? ??? ? case 4:{
- ?? ??? ??? ? ?? ??? ??? ?string adress;
- ?? ??? ??? ? ?? ??? ??? ?cout <<"请输入新地址:";?
- ?? ??? ??? ? ?? ??? ??? ?cin >> adress;
- ?? ??? ??? ? ?? ??? ??? ?B->data.adress = adress;
- ?? ??? ??? ??? ??? ? ? ?cout <<"修改完成!" << endl;
- ?? ??? ??? ??? ??? ??? ?break;
- ?? ??? ??? ??? ??? ? }
- ?? ??? ??? ??? ??? ? default:cout <<"序号输入错误,请重新输入!"<<endl;?
- ?? ??? ??? ??? ? }
- ?? ??? ??? ? }else{
- ?? ??? ??? ? ?? ?cout << "未查找到联系人!请重新输入!" << endl;?
- ?? ??? ??? ? }
- ?? ??? ??? ? ?
- ?? ??? ??? ?system("pause");
- ?? ??? ??? ?system("cls");
- ?? ??? ?}else if(i==4){
- ?? ??? ??? ?system("cls");
- ?? ??? ??? ?cout << "您选择了:查询选定联系人" <<endl;?
- ?? ??? ??? ? ? ?cout <<"---------根据姓名查询请输入1---------" << endl;
- ?? ??? ??? ??? ?cout <<"---------根据电话查询请输入2---------" << endl;?
- ?? ??? ??? ??? ?cout <<"---------根据生日查询请输入3---------" << endl;?
- ?? ??? ??? ??? ?cout <<"---------根据地址查询请输入4---------" << endl;
- ?? ??? ??? ??? ?int select;
- ?? ??? ??? ??? ?cout <<"请根据序号输入对象的进行查询:" ;
- ?? ??? ??? ? ?? ?cin >> select;
- ?? ??? ??? ? ?? ?switch(select){
- ?? ??? ??? ? ?? ??? ?case 1:{
- ?? ??? ??? ? ?? ??? ??? ?cout <<"请输入要查询的联系人姓名:" ;
- ?? ??? ??? ? ? ? ? ? ? ?string name;
- ?? ??? ??? ? ? ? ? ? ? ?cin >> name;
- ?? ??? ??? ? ? ? ? ? ? ?LinkList B;
- ?? ??? ??? ? ? ? ? ? ? ?B = SearchElemChar(L,1,name);
- ?? ??? ??? ? ? ? ? ? ? ?if(B){
- ?? ??? ??? ? ? ? ? ? ? ??? ?cout<<"查询成功!"<< endl;?
- ?? ??? ??? ? ? ? ? ? ? ??? ?cout<<"联系人姓名:"<< B->data.name << endl;
- ?? ??? ??? ? ? ? ? ? ? ??? ?cout<<"联系人电话:"<< B->data.number << endl;
- ?? ??? ??? ? ? ? ? ? ? ??? ?cout<<"联系人生日:"<< B->data.birthday << endl;
- ?? ??? ??? ? ? ? ? ? ? ??? ?cout<<"联系人地址:"<< B->data.adress << endl;
- ?? ??? ??? ? ? ? ? ? ? ??? ?cout<<"插入日期:"<< B->data.date << endl;
- ?? ??? ??? ??? ??? ? ? ? }else{
- ?? ??? ??? ??? ??? ? ? ? ?? ?cout<<"查询失败!请重新输入!"<< endl;?
- ?? ??? ??? ??? ??? ??? ? }
- ?? ??? ??? ??? ??? ??? ?break;
- ?? ??? ??? ??? ??? ? }
- ?? ??? ??? ??? ??? ? case 2:
- ?? ??? ??? ??? ??? ? ?? ?{
- ?? ??? ??? ??? ??? ? ?? ?cout <<"请输入要查询的联系人电话:" ;
- ?? ??? ??? ? ? ? ? ? ? ?string number;
- ?? ??? ??? ? ? ? ? ? ? ?cin >> number;
- ?? ??? ??? ? ? ? ? ? ? ?LinkList B;
- ?? ??? ??? ? ? ? ? ? ? ?B = SearchElemChar(L,5,number);
- ?? ??? ??? ? ? ? ? ? ? ?if(B){
- ?? ??? ??? ? ? ? ? ? ? ??? ?cout<<"查询成功!"<< endl;?
- ?? ??? ??? ? ? ? ? ? ? ??? ?cout<<"联系人姓名:"<< B->data.name << endl;
- ?? ??? ??? ? ? ? ? ? ? ??? ?cout<<"联系人电话:"<< B->data.number << endl;
- ?? ??? ??? ? ? ? ? ? ? ??? ?cout<<"联系人生日:"<< B->data.birthday << endl;
- ?? ??? ??? ? ? ? ? ? ? ??? ?cout<<"联系人地址:"<< B->data.adress << endl;
- ?? ??? ??? ? ? ? ? ? ? ??? ?cout<<"插入日期:"<< B->data.date << endl;
- ?? ??? ??? ??? ??? ? ? ? }else{
- ?? ??? ??? ??? ??? ? ? ? ?? ?cout<<"查询失败!请重新输入!"<< endl;?
- ?? ??? ??? ??? ??? ??? ? }
- ?? ??? ??? ??? ??? ??? ?break;
- ?? ??? ??? ??? ??? ??? ? }
- ?? ??? ??? ??? ??? ??? ?case 3:{
- ?? ??? ??? ??? ??? ??? ??? ?cout <<"请输入要查询的联系人生日:" ;
- ?? ??? ??? ? ? ? ? ? ? ?string bd;
- ?? ??? ??? ? ? ? ? ? ? ?cin >> bd;
- ?? ??? ??? ? ? ? ? ? ? ?LinkList B;
- ?? ??? ??? ? ? ? ? ? ? ?B = SearchElemChar(L,2,bd);
- ?? ??? ??? ? ? ? ? ? ? ?if(B){
- ?? ??? ??? ? ? ? ? ? ? ??? ?cout<<"查询成功!"<< endl;?
- ?? ??? ??? ? ? ? ? ? ? ??? ?cout<<"联系人姓名:"<< B->data.name << endl;
- ?? ??? ??? ? ? ? ? ? ? ??? ?cout<<"联系人电话:"<< B->data.number << endl;
- ?? ??? ??? ? ? ? ? ? ? ??? ?cout<<"联系人生日:"<< B->data.birthday << endl;
- ?? ??? ??? ? ? ? ? ? ? ??? ?cout<<"联系人地址:"<< B->data.adress << endl;
- ?? ??? ??? ? ? ? ? ? ? ??? ?cout<<"插入日期:"<< B->data.date << endl;
- ?? ??? ??? ??? ??? ? ? ? }else{
- ?? ??? ??? ??? ??? ? ? ? ?? ?cout<<"查询失败!请重新输入!"<< endl;?
- ?? ??? ??? ??? ??? ??? ? }
- ?? ??? ??? ??? ??? ??? ?break;
- ?? ??? ??? ??? ??? ??? ?}
- ?? ??? ??? ??? ??? ??? ?case 4:{
- ?? ??? ??? ??? ??? ??? ?cout <<"请输入要查询的联系人地址:" ;
- ?? ??? ??? ? ? ? ? ? ? ?string ad;
- ?? ??? ??? ? ? ? ? ? ? ?cin >> ad;
- ?? ??? ??? ? ? ? ? ? ? ?LinkList B;
- ?? ??? ??? ? ? ? ? ? ? ?B = SearchElemChar(L,3,ad);
- ?? ??? ??? ? ? ? ? ? ? ?if(B){
- ?? ??? ??? ? ? ? ? ? ? ??? ?cout<<"查询成功!"<< endl;?
- ?? ??? ??? ? ? ? ? ? ? ??? ?cout<<"联系人姓名:"<< B->data.name << endl;
- ?? ??? ??? ? ? ? ? ? ? ??? ?cout<<"联系人电话:"<< B->data.number << endl;
- ?? ??? ??? ? ? ? ? ? ? ??? ?cout<<"联系人生日:"<< B->data.birthday << endl;
- ?? ??? ??? ? ? ? ? ? ? ??? ?cout<<"联系人地址:"<< B->data.adress << endl;
- ?? ??? ??? ? ? ? ? ? ? ??? ?cout<<"插入日期:"<< B->data.date << endl;
- ?? ??? ??? ??? ??? ? ? ? }else{
- ?? ??? ??? ??? ??? ? ? ? ?? ?cout<<"查询失败!请重新输入!"<< endl;?
- ?? ??? ??? ??? ??? ??? ? }
- ?? ??? ??? ??? ??? ??? ?break;
- ?? ??? ??? ??? ??? ??? ??? ?break;
- ?? ??? ??? ??? ??? ??? ?}
- ?? ??? ??? ??? ??? ? default:cout <<"序号输入错误,请重新输入!"<<endl;?
- ?? ??? ??? ??? ? }?
- ?? ??? ? ? ?system("pause");
- ?? ??? ??? ?system("cls");
- ?? ??? ?}else if(i==5){
- ?? ??? ??? ?cout << "您选择了:删除联系人" <<endl;?
- ?? ??? ??? ?string name;
- ?? ??? ??? ?cout << "请输入联系人姓名:" <<endl;?
- ?? ??? ??? ?cin >> name;
- ?? ??? ??? ?LinkList D,P;
- ?? ??? ??? ?P = SearchElemBefore(L,name);?
- ?? ??? ??? ?if(P){
- ?? ??? ??? ??? ?D = P->next;
- ?? ??? ??? ?P->next = D->next;
- ?? ??? ??? ?delete D; //释放结点数据?
- ?? ??? ??? ?cout << "删除成功!" <<endl;
- ?? ??? ??? ?}else{
- ?? ??? ??? ??? ?cout<<"查询失败!未找到指定联系人!"<< endl;?
- ?? ??? ??? ?}
- ?? ??? ??? ?system("pause");
- ?? ??? ??? ?system("cls");
- ?? ??? ?}else if(i==6){
- ?? ??? ??? ?cout << "系统已退出,欢迎下次使用!" <<endl;
- ?? ??? ?}
- ?? ??? ?else{
- ?? ??? ??? ?cout <<"输入异常,请重新选择输入!" <<endl;
- ?? ??? ??? ?system("pause");
- ?? ??? ??? ?system("cls");
- ?? ??? ?}
- ?? ?}?
- ?? ?return 0;
- }
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持w3xue。