![帶有頭結(jié)點(diǎn)的鏈表基本操作與其能實(shí)現(xiàn)的數(shù)據(jù)結(jié)構(gòu),棧和隊(duì)列_第1頁(yè)](http://file4.renrendoc.com/view/cfb61518e3240b2e95ae5e935884aeab/cfb61518e3240b2e95ae5e935884aeab1.gif)
![帶有頭結(jié)點(diǎn)的鏈表基本操作與其能實(shí)現(xiàn)的數(shù)據(jù)結(jié)構(gòu),棧和隊(duì)列_第2頁(yè)](http://file4.renrendoc.com/view/cfb61518e3240b2e95ae5e935884aeab/cfb61518e3240b2e95ae5e935884aeab2.gif)
![帶有頭結(jié)點(diǎn)的鏈表基本操作與其能實(shí)現(xiàn)的數(shù)據(jù)結(jié)構(gòu),棧和隊(duì)列_第3頁(yè)](http://file4.renrendoc.com/view/cfb61518e3240b2e95ae5e935884aeab/cfb61518e3240b2e95ae5e935884aeab3.gif)
![帶有頭結(jié)點(diǎn)的鏈表基本操作與其能實(shí)現(xiàn)的數(shù)據(jù)結(jié)構(gòu),棧和隊(duì)列_第4頁(yè)](http://file4.renrendoc.com/view/cfb61518e3240b2e95ae5e935884aeab/cfb61518e3240b2e95ae5e935884aeab4.gif)
![帶有頭結(jié)點(diǎn)的鏈表基本操作與其能實(shí)現(xiàn)的數(shù)據(jù)結(jié)構(gòu),棧和隊(duì)列_第5頁(yè)](http://file4.renrendoc.com/view/cfb61518e3240b2e95ae5e935884aeab/cfb61518e3240b2e95ae5e935884aeab5.gif)
版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
.h#ifndefLIST_H_INCLUDED#defineLIST_H_INCLUDED本頭文件均為帶頭結(jié)點(diǎn)的單鏈表,功能函數(shù)包括對(duì)單鏈表的單個(gè)結(jié)點(diǎn)的修改,刪除等操作,包含對(duì)整個(gè)單鏈表整個(gè)操作單鏈表來(lái)實(shí)現(xiàn)棧,隊(duì)列等數(shù)據(jù)結(jié)構(gòu)*****/typedefintElemType;typedefintStatus;typedefstructLNode{ElemTypedata;structLNode*next;}LNode,*LinkList;typedefstructLStack{LinkListtop;}LStack,*PLStack;〃單鏈表實(shí)現(xiàn)棧typedefstructLQueue{LinkListFront;LinkListrear;}LQueue,*PLQueue;〃單鏈表實(shí)現(xiàn)隊(duì)列//單鏈表操作StatusInitList_L(LinkList&L);//構(gòu)造一個(gè)空的單鏈表StatusDestroyList_L(LinkList&L);//銷毀單鏈表LStatusClearList_L(LinkList&L);//將單鏈表置為空表intListLength_L(LinkListL);//求單鏈表的長(zhǎng)度LNode*Search_L(LinkListL,ElemTypee);/查找鏈表L第一個(gè)數(shù)據(jù)域?yàn)閑的元素,若不存在則返回NULLLNode*NextElem_L(LinkListp);〃返回p結(jié)點(diǎn)的直接后結(jié)點(diǎn)的指針,若P結(jié)點(diǎn)是尾元素結(jié)點(diǎn),則返回NULLLNode*MakeNode_L(ElemTypee);//構(gòu)造e結(jié)點(diǎn),返回指向該結(jié)點(diǎn)的指針StatusInsertAfter_L(LNode*p,LNode*q);//在p結(jié)點(diǎn)之后插入q結(jié)點(diǎn)StatusDeleteAfter_L(LNode*p,ElemType&e);//刪除結(jié)點(diǎn)P直接結(jié)點(diǎn)的后繼結(jié)點(diǎn),用e返回結(jié)點(diǎn)值,若p為空或指向尾結(jié)點(diǎn)則操作失敗voidListTraverse_L(LinkListL);//遍歷單鏈表//基于單鏈表的算法voidFind_SortList_L(LinkListL);〃鏈表中的元素排序,查找排序voidmaopao_SortList_L(LinkListL);//鏈表中的元素冒泡排序voidFast_SortList_L(LinkListL);//用快速排序?qū)︽湵碓嘏判騰oidInverseList(LinkListL);//單鏈表的重置。voidMergeList_L(LinkList&La,LinkList&Lb,LinkList&Lc);//將升序的單鏈表La與Lb歸并為新的單鏈表Lc//鏈棧StatusInitList_Stack(LStack&S);//初始化一個(gè)鏈棧StatusDestroyList_Stack(LStack&S);//銷毀一個(gè)鏈棧StatusStackEmpty_List(LStack&S);//l連棧是否為空voidClearStack_List(LStack&S);//青空鏈棧StatusPushStack_List(LStack&S,ElemTypee);/往主一個(gè)鏈棧中壓入元素eStatusPopStack_List(LStack&S,ElemType&e);//連棧頂元素出棧到eStatusgetTop_StackList(LStack&S,ElemType&e);/去鏈棧頂元素到e//隊(duì)列StatusInitList_Queue(LQueue&Q);//初始化一個(gè)循環(huán)鏈隊(duì)voidDestroyList_Queue(LQueue&Q);〃銷毀鏈隊(duì)voidClearList_Queue(LQueue&Q);//清空鏈隊(duì)StatusQueueEmpty_List(LQueue&Q);//對(duì)鏈隊(duì)判空intQueueLength_List(LQueueQ);//求鏈隊(duì)的長(zhǎng)度StatusPushQueue_List(LQueue&Q,ElemTypee);//將元素e入隊(duì)StatusPopQueue_List(LQueue&Q,ElemType&e);//隊(duì)頭元素出隊(duì)#endif//LIST_H_INCLUDED.cpp#include"List.h"#include<iostream>#include<malloc.h>#defineerror0#defineok1usingnamespacestd;StatusInitList_L(LinkList&L)//初始化一個(gè)帶頭結(jié)點(diǎn)的鏈表{L=(LinkList)malloc(sizeof(LNode));if(NULL==L){coutvv"初始化失?。?vvendl;returnerror;}L->next=NULL;coutvv"初始化成功!"vvendl;returnok;}StatusDestroyList_L(LinkList&L)//銷毀鏈表{LinkListp=L,q;while(p){q=p;p=p->next;free(q);}coutvv"銷毀鏈表!"vvendl;returnok;}StatusClearList_L(LinkList&L)//青空鏈表{LinkListp=L,q;while(p->next){q=p->next;p=p->next;free(q);}coutvv"清空鏈表!"vvendl;returnok;}intListLength_L(LinkListL)//求表長(zhǎng)度{LinkListp=L;intnum=0;while(p->next){p=p->next;++num;}returnnum;}LNode*Search_L(LinkListL,ElemTypee)//在表中查詢是否存在元素e,并返回該元素結(jié)點(diǎn){LinkListp=L->next;while(NULL!=p){if(p->data==e){coutvv"查詢成功!"vvendl;returnp;}elsep=p->next;}coutvv"不存在該元素!"vvendl;returnNULL;}LNode*MakeNode_L(ElemTypee)/構(gòu)造值為e的結(jié)點(diǎn),返回結(jié)點(diǎn)指針{LinkListp;p=(LinkList)malloc(sizeof(LNode));if(NULL==p){coutvv"創(chuàng)建結(jié)點(diǎn)失??!"vvendl;returnNULL;}elsep->data=e;returnp;}StatusInsertAfter_L(LNode*p,LNode*q)//在p結(jié)點(diǎn)之后插入q結(jié)點(diǎn){if(NULL==p||NULL==q)returnerror;q->next=p->next;p->next=q;coutvv"插入成功!"vvendl;returnok;StatusDeleteAfter_L(LNode*p,ElemType&e)/刪除結(jié)點(diǎn)P直接結(jié)點(diǎn)的后繼結(jié)點(diǎn),用e返回結(jié)點(diǎn)值,若p為空或指向尾結(jié)點(diǎn)則操作失敗{if(NULL==p){coutvv"刪除結(jié)點(diǎn)失??!"vvendl;returnerror;}LinkListq;q=p->next;p->next=q->next;free(q);coutvv"刪除成功!"vvendl;returnok;}voidListTraverse_L(LinkListL)//遍歷單鏈表{LinkListp=L->next;while(p){coutvvp->datavv"";p=p->next;}coutvvendl;}StatusInitList_Stack(LStack&S)//初始化一個(gè)鏈棧{S.top=(LinkList)malloc(sizeof(LNode));if(NULL==S.top)returnerror;coutvv"Initesuccess!"vvendl;S.top->next=NULL;returnok;}StatusDestroyList_Stack(LStack&S)//銷毀一個(gè)鏈棧{LinkListp=S.top,q;while(p){q=p;p=q->next;free(q);}returnok;}StatusStackEmpty_List(LStack&S)/鏈棧是否為空{(diào)if(NULL==S.top->next){coutvv"空棧!"vvendl;returnok;}elsereturnerror;}voidClearStack_List(LStack&S)//青空鏈棧{LinkListp=S.top->next,q;while(p){q=p;p=p->next;free(q);}}StatusPushStack_List(LStack&S,ElemTypee)/往主一個(gè)鏈棧中壓入元素e{LinkListq;q=(LinkList)malloc(sizeof(LNode));q->data=e;q->next=S.top->next;S.top->next=q;coutvv"Pushsuccess!"vvendl;returnok;}StatusPopStack_List(LStack&S,ElemType&e)/鏈棧頂元素出棧到e{LinkListq=S.top->next;if(NULL==q)returnerror;e=q->data;S.top->next=q->next;free(q);returnok;}StatusgetTop_StackList(LStack&S,ElemType&e)/去鏈棧頂元素到e{if(NULL==S.top->next)returnerror;e=S.top->next->data;returnok;}StatusInitList_Queue(LQueue&Q)//初始化一個(gè)循環(huán)鏈隊(duì){Q.Front=(LinkList)malloc(sizeof(LNode));if(NULL==Q.Front)returnerror;Q.Front->next=NULL;Q.rear=Q.Front->next;cout<<"InitListQueuesuccess!"<<endl;returnok;}voidDestroyList_Queue(LQueue&Q)//銷毀鏈隊(duì){LinkListp=Q.Front,q;while(p){q=p;p=p->next;free(q);}cout<<"DestroyListQueuesuccess!"<<endl;}voidClearList_Queue(LQueue&Q)//清空鏈隊(duì){LinkListp=Q.Front->next,q;while(p){q=p;p=p->next;free(q);}cout<<"clearListQueuesuccess!"<<endl;}StatusQueueEmpty_List(LQueue&Q)//對(duì)鏈隊(duì)判空{(diào)if(Q.Front->next==Q.rear)returnok;elsereturnerror;}intQueueLength_List(LQueueQ)〃求鏈隊(duì)的長(zhǎng)度{intnum=0;num=ListLength_L(Q.Front);returnnum;}StatusPushQueue_List(LQueue&Q,ElemTypee)//|將元素e入隊(duì){LinkListq;q=(LinkList)malloc(sizeof(LNode));if(NULL==q)returnerror;q->data=e;q->next=NULL;if(Q.rear==NULL)Q.rear=Q.Front;Q.rear->next=q;Q.rear=q;returnok;}StatusPopQueue_List(LQueue&Q,ElemType&e)//隊(duì)頭元素出隊(duì){if(QueueEmpty_List(Q))returnerror;LinkListq=Q.Front->next;e=q->data;Q.Front->next=q->next;free(q);returnok;}voidmaopao_SortList_L(LinkListL)〃鏈表中的元素排序,冒泡排序{ElemTypee;LinkListp=L->next,temp;while(p){temp=p->next;while(temp){if(p->data>temp->data)e=p->data,p->data=temp->data,temp->data=e;temp=temp->next;p=p->next;}voidFind_SortList_L(LinkListL)〃鏈表中的元素排序,查找排序{LinkListp=L->next,temp,q;ElemTypee
溫馨提示
- 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 電商平臺(tái)的會(huì)員制度設(shè)計(jì)與管理策略
- 現(xiàn)代營(yíng)銷思維下的教育領(lǐng)域網(wǎng)絡(luò)營(yíng)銷
- 物聯(lián)網(wǎng)行業(yè)國(guó)際品牌的智慧化營(yíng)銷戰(zhàn)略研究
- 現(xiàn)代物流信息技術(shù)的教育意義與前景
- 用戶體驗(yàn)在市場(chǎng)營(yíng)銷中的戰(zhàn)略規(guī)劃
- 珠寶教育培養(yǎng)新一代的珠寶行業(yè)人才
- 2025年丹東貨運(yùn)從業(yè)資格證模擬考試下載安裝
- 現(xiàn)代保安公司在辦公環(huán)境中的服務(wù)模式創(chuàng)新
- 班級(jí)文化的傳承與學(xué)校歷史發(fā)展
- 電商平臺(tái)的創(chuàng)新與業(yè)務(wù)拓展案例探討
- ## 外事領(lǐng)域意識(shí)形態(tài)工作預(yù)案
- CJJ 169-2012城鎮(zhèn)道路路面設(shè)計(jì)規(guī)范
- 第八單元金屬和金屬材料單元復(fù)習(xí)題-2023-2024學(xué)年九年級(jí)化學(xué)人教版下冊(cè)
- 鋼鐵是怎樣煉成的保爾成長(zhǎng)史
- 精神科護(hù)理技能5.3出走行為的防范與護(hù)理
- 煤礦機(jī)電運(yùn)輸培訓(xùn)課件
- 采購(gòu)管理學(xué)教學(xué)課件
- 《供應(yīng)商質(zhì)量會(huì)議》課件
- 江蘇省科技企業(yè)孵化器孵化能力評(píng)價(jià)研究的中期報(bào)告
- 供應(yīng)商審核培訓(xùn)教程
- 酒精性肝硬化伴食管胃底靜脈曲張破裂出血的護(hù)理查房
評(píng)論
0/150
提交評(píng)論