C++使用鏈表存儲實(shí)現(xiàn)通訊錄功能管理
本文實(shí)例為大家分享了C++使用鏈表存儲實(shí)現(xiàn)通訊錄功能管理的具體代碼,供大家參考,具體內(nèi)容如下
簡介
這是第二周老師給的一個(gè)小項(xiàng)目要求實(shí)現(xiàn)基本通訊錄功能,有數(shù)據(jù)的增刪改查,包含插入時(shí)間的能力。
代碼詳情
頭文件
#include <iostream> #include <string> #include<malloc.h> //system功能調(diào)用? #include <windows.h> //使用本地系統(tǒng)API獲取插入時(shí)間? #include <sstream>
基本存儲結(jié)構(gòu)體
typedef struct info{ ?? ?string number; ?? ?string date; ?? ?string name; ?? ?string adress; ?? ?string birthday;? }A; typedef struct LNode{ ?? ?A data;? ? ? struct LNode *next; }LNode,*LinkList;
鏈表數(shù)據(jù)初始化
用前插法插入數(shù)據(jù)
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){ //考慮使用數(shù)組來賦值? ?? ?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調(diào)用插入時(shí)間
SYSTEMTIME sys;? GetLocalTime( &sys ); string y = doubleToString(sys.wYear); string m = doubleToString(sys.wMonth); string d = doubleToString(sys.wDay); string ymd = y+"-"+m+"-"+d;
因?yàn)楂@取的是一個(gè)double值,您得對其時(shí)間強(qiáng)制類型轉(zhuǎn)換
string doubleToString(double num) { //強(qiáng)制類型轉(zhuǎn)換 double強(qiáng)制轉(zhuǎn)換為string類型? ? ? stringstream ss; ? ? string str; ? ? ss << num; ? ? ss >> str; ? ? return str; }
數(shù)據(jù)查詢功能
LinkList SearchElemChar(LinkList L,int i,string e){ //思路,傳遞參數(shù)1,2,3,4,eg 1代表name,再分不同的方法在鏈表內(nèi)循環(huán)查找操作? ?if (i == 1){ //查名字? ??? ?while(L!= NULL){ ??? ??? ?if(L->data.name == e){ ??? ??? ??? ?return L;? ?? ??? ? }else{ ?? ??? ? L = L->next; ?? ??? ? } ??? ??? ?} ??? ??? ?if(L = NULL){ ??? ??? ??? ?cout << "未查到數(shù)據(jù)!"<<endl; ?? ??? ? } ?}else if(i == 2){//查生日? ??? ?while(L!= NULL){ ??? ??? ?if(L->data.birthday == e){ ??? ??? ??? ?return L;? ?? ??? ? }else{ ?? ??? ? L = L->next; ?? ??? ? } ??? ??? ?} ??? ??? ?if(L = NULL){ ??? ??? ?cout <<"未查到數(shù)據(jù)!"<<endl; ?? ??? ? } ?} ?else if(i == 3){//查地址? ??? ?while(L!= NULL){ ??? ??? ?if(L->data.adress == e){ ??? ??? ??? ?return L;? ?? ??? ? }else{ ?? ??? ? L = L->next; ?? ??? ? } ??? ??? ?} ??? ??? ?if(L = NULL){ ??? ??? ?cout <<"未查到數(shù)據(jù)!"<<endl; ?? ??? ? } ?}else if(i == 4){//查時(shí)間? ??? ?while(L!= NULL){ ??? ??? ?if(L->data.date == e){ ??? ??? ??? ?return L;? ?? ??? ? }else{ ?? ??? ? L = L->next; ?? ??? ? } ??? ??? ?} ??? ??? ?if(L = NULL){ ??? ??? ?cout <<"未查到數(shù)據(jù)!"<<endl; ?? ??? ? } ?} ?else if(i == 5){//查電話? ??? ?while(L!= NULL){ ??? ??? ?if(L->data.number == e){ ??? ??? ??? ?return L;? ?? ??? ? }else{ ?? ??? ? L = L->next; ?? ??? ? } ??? ??? ?} ??? ??? ?if(L = NULL){ ??? ??? ?cout <<"未查到數(shù)據(jù)!"<<endl; ?? ??? ? } ?} ? }?
完整案例
//樂公第二周項(xiàng)目 實(shí)現(xiàn)基本通訊錄存儲結(jié)構(gòu)? //基礎(chǔ)鏈表存儲數(shù)據(jù) #include <iostream> #include <string> #include<malloc.h> //system功能調(diào)用? #include <windows.h> //使用本地系統(tǒng)API獲取插入時(shí)間? #include <sstream> #define ERROR 0 #define OK 1 using namespace std; typedef ?int ElemType; /*定義表元素的類型*/ //結(jié)構(gòu)體文件 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){ //考慮使用數(shù)組來賦值? ?? ?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){ //思路,傳遞參數(shù)1,2,3,4,eg 1代表name,再分不同的方法在鏈表內(nèi)循環(huán)查找操作? ?if (i == 1){ //查名字? ??? ?while(L!= NULL){ ??? ??? ?if(L->data.name == e){ ??? ??? ??? ?return L;? ?? ??? ? }else{ ?? ??? ? L = L->next; ?? ??? ? } ??? ??? ?} ??? ??? ?if(L = NULL){ ??? ??? ??? ?cout << "未查到數(shù)據(jù)!"<<endl; ?? ??? ? } ?}else if(i == 2){//查生日? ??? ?while(L!= NULL){ ??? ??? ?if(L->data.birthday == e){ ??? ??? ??? ?return L;? ?? ??? ? }else{ ?? ??? ? L = L->next; ?? ??? ? } ??? ??? ?} ??? ??? ?if(L = NULL){ ??? ??? ?cout <<"未查到數(shù)據(jù)!"<<endl; ?? ??? ? } ?} ?else if(i == 3){//查地址? ??? ?while(L!= NULL){ ??? ??? ?if(L->data.adress == e){ ??? ??? ??? ?return L;? ?? ??? ? }else{ ?? ??? ? L = L->next; ?? ??? ? } ??? ??? ?} ??? ??? ?if(L = NULL){ ??? ??? ?cout <<"未查到數(shù)據(jù)!"<<endl; ?? ??? ? } ?}else if(i == 4){//查時(shí)間? ??? ?while(L!= NULL){ ??? ??? ?if(L->data.date == e){ ??? ??? ??? ?return L;? ?? ??? ? }else{ ?? ??? ? L = L->next; ?? ??? ? } ??? ??? ?} ??? ??? ?if(L = NULL){ ??? ??? ?cout <<"未查到數(shù)據(jù)!"<<endl; ?? ??? ? } ?} ?else if(i == 5){//查電話? ??? ?while(L!= NULL){ ??? ??? ?if(L->data.number == e){ ??? ??? ??? ?return L;? ?? ??? ? }else{ ?? ??? ? L = L->next; ?? ??? ? } ??? ??? ?} ??? ??? ?if(L = NULL){ ??? ??? ?cout <<"未查到數(shù)據(jù)!"<<endl; ?? ??? ? } ?} ? }? LinkList SearchElemBefore(LinkList L,string e){ //刪除結(jié)點(diǎn)必須返回前個(gè)結(jié)點(diǎn)的地址,這里查找前個(gè)結(jié)點(diǎn)? ? ? ?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<<"------歡迎您使用樂公通訊錄系統(tǒng)!------"<< endl; ?? ?cout <<"-----請根據(jù)功能輸入對應(yīng)的序號--------" <<endl;? ?? ?cout <<"-----------1.新建聯(lián)系人--------------" <<endl;? ?? ?cout <<"--------2.查看所有聯(lián)系人-------------" <<endl;? ?? ?cout <<"--------3.修改選定聯(lián)系人-------------" <<endl; ?? ?cout <<"--------4.查詢選定聯(lián)系人-------------" <<endl; ?? ?cout <<"--------5.刪除選定聯(lián)系人-------------" <<endl; ?? ?cout <<"------------6.退出系統(tǒng)---------------" <<endl;? ?? ?cout << "請您輸入序號并按回車進(jìn)入:" ;? ?? ?cin >> a; ?? ?return a; } string doubleToString(double num) { //強(qiáng)制類型轉(zhuǎn)換 double強(qiáng)制轉(zhuǎn)換為string類型? ? ? stringstream ss; ? ? string str; ? ? ss << num; ? ? ss >> str; ? ? return str; } void foreachelem(LinkList L){ ?? ?if(L->next == NULL){ ?? ??? ?cout<<"通訊錄里還沒有聯(lián)系人,快去新建一下吧~"<<endl;? ?? ?}else{ ?? ?while(L->next!=NULL){ ?? ??? ?L=L->next; ?? ??? ?cout<< "聯(lián)系人姓名:" << L->data.name <<endl; ?? ??? ?cout<< "聯(lián)系人電話:" << L->data.number<<endl; ?? ??? ?cout<< "聯(lián)系人地址:" << L->data.adress <<endl; ?? ??? ?cout<< "聯(lián)系人生日:" << L->data.birthday <<endl; ?? ??? ?cout<< "錄入時(shí)間:" << L->data.date <<endl; ?? ?} ?? ?cout<< "\n"; } //system("pause"); } int serachsamename(LinkList L,string name){ //查找是否存在姓名相同的聯(lián)系人? ?? ?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 << "您選擇了:新建聯(lián)系人" <<endl;? ?? ??? ??? ?string number; ?? ??? ??? ?string date; ?? ? ? ? ? ?string time; ?? ? ? ? ? ?string name; ?? ? ? ? ? ?string adress; ?? ? ? ? ? ?string birthday;? ?? ? ? ? ? ?cout << "請輸入聯(lián)系人姓名:";? ?? ??? ??? ?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 << "聯(lián)系人姓名重復(fù),請刪除舊聯(lián)系人或更改姓名!" << endl;? ?? ??? ??? ? }else{ ?? ??? ??? ? ?? ?cout << "請輸入聯(lián)系人電話:";? ?? ??? ??? ? ? ?cin >> number; ? ? ? ? ? ? if(number.size()!=11){ ? ? ? ? ? ? ?? ?cout << "手機(jī)號輸入有誤,請大于11位!" << endl;?? ? ?? ??? ??? ?}else{ ?? ??? ??? ??? ?cout << "請輸入聯(lián)系人生日:";? ?? ??? ??? ?cin >> birthday; ?? ??? ??? ?cout << "請輸入聯(lián)系人地址:";? ?? ??? ??? ?cin >> adress; ?? ??? ??? ??? ?cout << "聯(lián)系人于" << 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 << "您選擇了:遍歷聯(lián)系人" <<endl;? ?? ??? ??? ?foreachelem(L); ?? ??? ??? ?system("pause"); ?? ??? ??? ?system("cls"); ?? ??? ??? ? ?? ??? ?}else if(i==3){ ?? ??? ??? ?cout << "您選擇了:修改選定聯(lián)系人" <<endl;? ?? ??? ??? ?cout <<"請輸入要修改的聯(lián)系人姓名:" ; ?? ??? ??? ?string name; ?? ??? ??? ?cin >> name; ?? ??? ??? ?LinkList B; ?? ??? ??? ?B = SearchElemChar(L,1,name); ?? ??? ??? ? if(B){ ?? ??? ??? ? ?? ?system("cls"); ?? ??? ??? ? ?? ?cout << "聯(lián)系人查找成功!姓名:" << B->data.name << endl;? ?? ??? ??? ? ?? ?int select; ?? ??? ??? ? ?? ?cout <<"---------修改姓名請輸入1---------" << endl; ?? ??? ??? ??? ?cout <<"---------修改電話請輸入2---------" << endl;? ?? ??? ??? ??? ?cout <<"---------修改生日請輸入3---------" << endl;? ?? ??? ??? ??? ?cout <<"---------修改地址請輸入4---------" << endl;? ?? ??? ??? ? ?? ?cout <<"請根據(jù)序號輸入對象的選項(xiàng)修改:" ; ?? ??? ??? ? ?? ?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 << "手機(jī)號輸入有誤,請大于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 <<"序號輸入錯(cuò)誤,請重新輸入!"<<endl;? ?? ??? ??? ??? ? } ?? ??? ??? ? }else{ ?? ??? ??? ? ?? ?cout << "未查找到聯(lián)系人!請重新輸入!" << endl;? ?? ??? ??? ? } ?? ??? ??? ? ? ?? ??? ??? ?system("pause"); ?? ??? ??? ?system("cls"); ?? ??? ?}else if(i==4){ ?? ??? ??? ?system("cls"); ?? ??? ??? ?cout << "您選擇了:查詢選定聯(lián)系人" <<endl;? ?? ??? ??? ? ? ?cout <<"---------根據(jù)姓名查詢請輸入1---------" << endl; ?? ??? ??? ??? ?cout <<"---------根據(jù)電話查詢請輸入2---------" << endl;? ?? ??? ??? ??? ?cout <<"---------根據(jù)生日查詢請輸入3---------" << endl;? ?? ??? ??? ??? ?cout <<"---------根據(jù)地址查詢請輸入4---------" << endl; ?? ??? ??? ??? ?int select; ?? ??? ??? ??? ?cout <<"請根據(jù)序號輸入對象的進(jìn)行查詢:" ; ?? ??? ??? ? ?? ?cin >> select; ?? ??? ??? ? ?? ?switch(select){ ?? ??? ??? ? ?? ??? ?case 1:{ ?? ??? ??? ? ?? ??? ??? ?cout <<"請輸入要查詢的聯(lián)系人姓名:" ; ?? ??? ??? ? ? ? ? ? ? ?string name; ?? ??? ??? ? ? ? ? ? ? ?cin >> name; ?? ??? ??? ? ? ? ? ? ? ?LinkList B; ?? ??? ??? ? ? ? ? ? ? ?B = SearchElemChar(L,1,name); ?? ??? ??? ? ? ? ? ? ? ?if(B){ ?? ??? ??? ? ? ? ? ? ? ??? ?cout<<"查詢成功!"<< endl;? ?? ??? ??? ? ? ? ? ? ? ??? ?cout<<"聯(lián)系人姓名:"<< B->data.name << endl; ?? ??? ??? ? ? ? ? ? ? ??? ?cout<<"聯(lián)系人電話:"<< B->data.number << endl; ?? ??? ??? ? ? ? ? ? ? ??? ?cout<<"聯(lián)系人生日:"<< B->data.birthday << endl; ?? ??? ??? ? ? ? ? ? ? ??? ?cout<<"聯(lián)系人地址:"<< B->data.adress << endl; ?? ??? ??? ? ? ? ? ? ? ??? ?cout<<"插入日期:"<< B->data.date << endl; ?? ??? ??? ??? ??? ? ? ? }else{ ?? ??? ??? ??? ??? ? ? ? ?? ?cout<<"查詢失?。≌堉匦螺斎?!"<< endl;? ?? ??? ??? ??? ??? ??? ? } ?? ??? ??? ??? ??? ??? ?break; ?? ??? ??? ??? ??? ? } ?? ??? ??? ??? ??? ? case 2: ?? ??? ??? ??? ??? ? ?? ?{ ?? ??? ??? ??? ??? ? ?? ?cout <<"請輸入要查詢的聯(lián)系人電話:" ; ?? ??? ??? ? ? ? ? ? ? ?string number; ?? ??? ??? ? ? ? ? ? ? ?cin >> number; ?? ??? ??? ? ? ? ? ? ? ?LinkList B; ?? ??? ??? ? ? ? ? ? ? ?B = SearchElemChar(L,5,number); ?? ??? ??? ? ? ? ? ? ? ?if(B){ ?? ??? ??? ? ? ? ? ? ? ??? ?cout<<"查詢成功!"<< endl;? ?? ??? ??? ? ? ? ? ? ? ??? ?cout<<"聯(lián)系人姓名:"<< B->data.name << endl; ?? ??? ??? ? ? ? ? ? ? ??? ?cout<<"聯(lián)系人電話:"<< B->data.number << endl; ?? ??? ??? ? ? ? ? ? ? ??? ?cout<<"聯(lián)系人生日:"<< B->data.birthday << endl; ?? ??? ??? ? ? ? ? ? ? ??? ?cout<<"聯(lián)系人地址:"<< B->data.adress << endl; ?? ??? ??? ? ? ? ? ? ? ??? ?cout<<"插入日期:"<< B->data.date << endl; ?? ??? ??? ??? ??? ? ? ? }else{ ?? ??? ??? ??? ??? ? ? ? ?? ?cout<<"查詢失敗!請重新輸入!"<< endl;? ?? ??? ??? ??? ??? ??? ? } ?? ??? ??? ??? ??? ??? ?break; ?? ??? ??? ??? ??? ??? ? } ?? ??? ??? ??? ??? ??? ?case 3:{ ?? ??? ??? ??? ??? ??? ??? ?cout <<"請輸入要查詢的聯(lián)系人生日:" ; ?? ??? ??? ? ? ? ? ? ? ?string bd; ?? ??? ??? ? ? ? ? ? ? ?cin >> bd; ?? ??? ??? ? ? ? ? ? ? ?LinkList B; ?? ??? ??? ? ? ? ? ? ? ?B = SearchElemChar(L,2,bd); ?? ??? ??? ? ? ? ? ? ? ?if(B){ ?? ??? ??? ? ? ? ? ? ? ??? ?cout<<"查詢成功!"<< endl;? ?? ??? ??? ? ? ? ? ? ? ??? ?cout<<"聯(lián)系人姓名:"<< B->data.name << endl; ?? ??? ??? ? ? ? ? ? ? ??? ?cout<<"聯(lián)系人電話:"<< B->data.number << endl; ?? ??? ??? ? ? ? ? ? ? ??? ?cout<<"聯(lián)系人生日:"<< B->data.birthday << endl; ?? ??? ??? ? ? ? ? ? ? ??? ?cout<<"聯(lián)系人地址:"<< B->data.adress << endl; ?? ??? ??? ? ? ? ? ? ? ??? ?cout<<"插入日期:"<< B->data.date << endl; ?? ??? ??? ??? ??? ? ? ? }else{ ?? ??? ??? ??? ??? ? ? ? ?? ?cout<<"查詢失敗!請重新輸入!"<< endl;? ?? ??? ??? ??? ??? ??? ? } ?? ??? ??? ??? ??? ??? ?break; ?? ??? ??? ??? ??? ??? ?} ?? ??? ??? ??? ??? ??? ?case 4:{ ?? ??? ??? ??? ??? ??? ?cout <<"請輸入要查詢的聯(lián)系人地址:" ; ?? ??? ??? ? ? ? ? ? ? ?string ad; ?? ??? ??? ? ? ? ? ? ? ?cin >> ad; ?? ??? ??? ? ? ? ? ? ? ?LinkList B; ?? ??? ??? ? ? ? ? ? ? ?B = SearchElemChar(L,3,ad); ?? ??? ??? ? ? ? ? ? ? ?if(B){ ?? ??? ??? ? ? ? ? ? ? ??? ?cout<<"查詢成功!"<< endl;? ?? ??? ??? ? ? ? ? ? ? ??? ?cout<<"聯(lián)系人姓名:"<< B->data.name << endl; ?? ??? ??? ? ? ? ? ? ? ??? ?cout<<"聯(lián)系人電話:"<< B->data.number << endl; ?? ??? ??? ? ? ? ? ? ? ??? ?cout<<"聯(lián)系人生日:"<< B->data.birthday << endl; ?? ??? ??? ? ? ? ? ? ? ??? ?cout<<"聯(lián)系人地址:"<< B->data.adress << endl; ?? ??? ??? ? ? ? ? ? ? ??? ?cout<<"插入日期:"<< B->data.date << endl; ?? ??? ??? ??? ??? ? ? ? }else{ ?? ??? ??? ??? ??? ? ? ? ?? ?cout<<"查詢失??!請重新輸入!"<< endl;? ?? ??? ??? ??? ??? ??? ? } ?? ??? ??? ??? ??? ??? ?break; ?? ??? ??? ??? ??? ??? ??? ?break; ?? ??? ??? ??? ??? ??? ?} ?? ??? ??? ??? ??? ? default:cout <<"序號輸入錯(cuò)誤,請重新輸入!"<<endl;? ?? ??? ??? ??? ? }? ?? ??? ? ? ?system("pause"); ?? ??? ??? ?system("cls"); ?? ??? ?}else if(i==5){ ?? ??? ??? ?cout << "您選擇了:刪除聯(lián)系人" <<endl;? ?? ??? ??? ?string name; ?? ??? ??? ?cout << "請輸入聯(lián)系人姓名:" <<endl;? ?? ??? ??? ?cin >> name; ?? ??? ??? ?LinkList D,P; ?? ??? ??? ?P = SearchElemBefore(L,name);? ?? ??? ??? ?if(P){ ?? ??? ??? ??? ?D = P->next; ?? ??? ??? ?P->next = D->next; ?? ??? ??? ?delete D; //釋放結(jié)點(diǎn)數(shù)據(jù)? ?? ??? ??? ?cout << "刪除成功!" <<endl; ?? ??? ??? ?}else{ ?? ??? ??? ??? ?cout<<"查詢失??!未找到指定聯(lián)系人!"<< endl;? ?? ??? ??? ?} ?? ??? ??? ?system("pause"); ?? ??? ??? ?system("cls"); ?? ??? ?}else if(i==6){ ?? ??? ??? ?cout << "系統(tǒng)已退出,歡迎下次使用!" <<endl; ?? ??? ?} ?? ??? ?else{ ?? ??? ??? ?cout <<"輸入異常,請重新選擇輸入!" <<endl; ?? ??? ??? ?system("pause"); ?? ??? ??? ?system("cls"); ?? ??? ?} ?? ?}? ?? ?return 0; }
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
在Vitis?IDE中如何使用第三方庫?libtiff?保存?tiff?文件
這篇文章主要介紹了在Vitis?IDE中如何使用第三方庫?libtiff?保存?tiff?文件,本文通過圖文實(shí)例相結(jié)合給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2023-07-07解析C++編程中如何使用設(shè)計(jì)模式中的狀態(tài)模式結(jié)構(gòu)
這篇文章主要介紹了如何在C++編程中適用設(shè)計(jì)模式中的狀態(tài)模式結(jié)構(gòu),狀態(tài)模式強(qiáng)調(diào)將特定狀態(tài)相關(guān)的邏輯分散到一些類的狀態(tài)類中,需要的朋友可以參考下2016-03-03C語言 數(shù)據(jù)結(jié)構(gòu)之鏈表實(shí)現(xiàn)代碼
這篇文章主要介紹了C語言 數(shù)據(jù)結(jié)構(gòu)之鏈表實(shí)現(xiàn)代碼的相關(guān)資料,需要的朋友可以參考下2016-10-10淺談C語言共用體和與結(jié)構(gòu)體的區(qū)別
下面小編就為大家?guī)硪黄獪\談C語言共用體和與結(jié)構(gòu)體的區(qū)別。小編覺得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2017-02-02C++實(shí)現(xiàn)LeetCode(154.尋找旋轉(zhuǎn)有序數(shù)組的最小值之二)
這篇文章主要介紹了C++實(shí)現(xiàn)LeetCode(154.尋找旋轉(zhuǎn)有序數(shù)組的最小值之二),本篇文章通過簡要的案例,講解了該項(xiàng)技術(shù)的了解與使用,以下就是詳細(xì)內(nèi)容,需要的朋友可以參考下2021-07-07