資源描述:
《循環(huán)鏈表c代碼含注釋級(jí)程序圖解實(shí)現(xiàn)信息管理系統(tǒng)插入,刪除,查詢,文件讀取,存儲(chǔ),有序歸并,輸出》由會(huì)員上傳分享,免費(fèi)在線閱讀,更多相關(guān)內(nèi)容在工程資料-天天文庫(kù)。
1、廣使用循環(huán)雙向鏈表,實(shí)現(xiàn)名勝信息管理系統(tǒng),可實(shí)現(xiàn)插入,刪除,查詢,文件讀取,存儲(chǔ),有序歸并,輸出的功能”/head-length#include#include#includeusingnamespacestd;classCScene〃景點(diǎn)類private:stringname;stringcity;floatticket;friendclassCSceneNode;friendclassCSceneList;friendclassCSceneView;//景點(diǎn)名〃所在城市〃票價(jià)〃結(jié)點(diǎn)友元類〃鏈表友元類〃視圖友元類public:CS
2、cene():name(',unknownH),city(,,unknown,,),ticket(0){}〃構(gòu)造函數(shù)CScene(CScene&s){name=s.name;city=s.city;ticket=s.ticket;}//拷貝構(gòu)造函數(shù)CScene(stringn,stringc,floatt){name=n;city=c;ticket=t;〃構(gòu)造函數(shù)voidOutputScene(){cout?name?"t"?city?',t,,?ticket?endl;cout?""?endl;}〃輸出函數(shù)voidlnput()〃輸入{coutvv”請(qǐng)依次輸入名勝名稱,所在城帀,
3、票價(jià)”vvendl;cin?name?city?ticket;}classCSceneNode//結(jié)點(diǎn)類private:scene;*prior;*next;CSceneList;CSceneView;〃內(nèi)嵌對(duì)象〃指向前驅(qū)〃指向后繼〃鏈表友元類〃視圖友元類〃構(gòu)造函數(shù)〃構(gòu)造函數(shù)CSceneCSceneNodeCSceneNodefriendclassfriendclasspublic:CSceneNode():next(NULL),prior(NULL),scene(){}CSceneNode(CScenes):next(NULL),prior(NULL),scene(s){}};cla
4、ssCSceneListr〃鏈表類{private:stringlistname;〃鏈表名intlength;〃表長(zhǎng)CSceneNode*head;〃頭指針friendclassCSceneView;〃視圖友元類public:CSceneList():listname("未分類M),length(O)〃構(gòu)造函數(shù)head=newCSceneNode;head->prior=head;head->next=head;}?CSceneList()〃析構(gòu)函數(shù){CSceneNode*p,*q;for(p=head->next;p!=head;p=q){q=p->next;deletep;}del
5、etehead;head=NULL;}voidOutput()〃輸岀全部{cout?n"?endl;cout?listname?H全部景點(diǎn)H?endl;cout?Hn?endl;CSceneNode*p;intj;for(p=head->next,j=1;p!=head;p=p->next,j++){cout?j?"tH?p->scene.namevv”t”vvp?>scene.cityvv”t”vvp?>scene.ticketvvendl;cout?""?endl;}cout?n總數(shù)"?length?endl;boollnsertHead(CSceneseene){CScen
6、eNode*pNew=newCSceneNode(scene);〃表頭插入,可用任意位習(xí)插入函數(shù)代替其功能〃川請(qǐng)新結(jié)點(diǎn)if(!pNew){coutvv”內(nèi)存申請(qǐng)失敗,插入失??!“vvendl;returnfalse;}pNew->prior=head;pNew->next=head->next;head->next->prior=pNew;head->next=pNew;〃修改新結(jié)點(diǎn)〃修改新結(jié)點(diǎn)〃修改鄰近結(jié)點(diǎn)〃修改頭結(jié)點(diǎn)length++;cout?HlnsertedA.A,,?endl;〃表長(zhǎng)加一returntrue;}booIInsertTail(CSceneseene){CScen
7、eNode*pNew=newCSceneNode(scene);〃表尾插入〃申請(qǐng)新結(jié)點(diǎn)if(!pNew){cout?"內(nèi)存中請(qǐng)失敗,插入失??!“vvendl;returnfalse;}pNew->next=head;pNew->prior=head->prior;〃修改新結(jié)點(diǎn)〃修改新結(jié)點(diǎn)head->prior->next=pNew;head->prior=pNew;length++;returntrue;}//修改原末纟占人I〃修改頭結(jié)點(diǎn)〃表長(zhǎng)