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 <<"序號輸入錯誤,請重新輸入!"<<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 <<"序號輸入錯誤,請重新輸入!"<<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)文章
C/C++函數(shù)調(diào)用棧的實(shí)現(xiàn)方法
這篇文章主要介紹了C/C++函數(shù)調(diào)用棧的實(shí)現(xiàn)方法,可實(shí)現(xiàn)一個(gè)簡單的腳本解釋器,具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2014-10-10
C語言實(shí)現(xiàn)字母大小寫轉(zhuǎn)換的方法
這篇文章主要介紹了C語言實(shí)現(xiàn)字母大小寫轉(zhuǎn)換的方法,涉及C語言字符串的遍歷與轉(zhuǎn)換技巧,非常簡單實(shí)用,需要的朋友可以參考下2015-07-07
C語言學(xué)習(xí)進(jìn)階篇之萬字詳解指針與qsort函數(shù)
之前的指針詳解中,提到過qsort函數(shù),這個(gè)函數(shù)是用來排序的,下面這篇文章主要給大家介紹了關(guān)于C語言指針與qsort函數(shù)的相關(guān)資料,文中通過實(shí)例代碼介紹的非常詳細(xì),需要的朋友可以參考下2022-08-08
VC++實(shí)現(xiàn)文件與應(yīng)用程序關(guān)聯(lián)的方法(注冊表修改)
這篇文章主要介紹了VC++實(shí)現(xiàn)文件與應(yīng)用程序關(guān)聯(lián)的方法,涉及VC++針對注冊表的相關(guān)操作技巧,需要的朋友可以參考下2016-08-08
深入線性時(shí)間復(fù)雜度求數(shù)組中第K大數(shù)的方法詳解
本篇文章是對線性時(shí)間復(fù)雜度求數(shù)組中第K大數(shù)的方法進(jìn)行了詳細(xì)的分析介紹,需要的朋友參考下2013-05-05

