![堆棧隊(duì)列字符串匹配相關(guān)算法實(shí)現(xiàn)(共17頁)_第1頁](http://file3.renrendoc.com/fileroot_temp3/2022-2/24/1fb9c2d2-554a-4219-85d4-ea90624d4034/1fb9c2d2-554a-4219-85d4-ea90624d40341.gif)
![堆棧隊(duì)列字符串匹配相關(guān)算法實(shí)現(xiàn)(共17頁)_第2頁](http://file3.renrendoc.com/fileroot_temp3/2022-2/24/1fb9c2d2-554a-4219-85d4-ea90624d4034/1fb9c2d2-554a-4219-85d4-ea90624d40342.gif)
![堆棧隊(duì)列字符串匹配相關(guān)算法實(shí)現(xiàn)(共17頁)_第3頁](http://file3.renrendoc.com/fileroot_temp3/2022-2/24/1fb9c2d2-554a-4219-85d4-ea90624d4034/1fb9c2d2-554a-4219-85d4-ea90624d40343.gif)
![堆棧隊(duì)列字符串匹配相關(guān)算法實(shí)現(xiàn)(共17頁)_第4頁](http://file3.renrendoc.com/fileroot_temp3/2022-2/24/1fb9c2d2-554a-4219-85d4-ea90624d4034/1fb9c2d2-554a-4219-85d4-ea90624d40344.gif)
![堆棧隊(duì)列字符串匹配相關(guān)算法實(shí)現(xiàn)(共17頁)_第5頁](http://file3.renrendoc.com/fileroot_temp3/2022-2/24/1fb9c2d2-554a-4219-85d4-ea90624d4034/1fb9c2d2-554a-4219-85d4-ea90624d40345.gif)
版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡介
1、精選優(yōu)質(zhì)文檔-傾情為你奉上堆棧、隊(duì)列、字符串匹配相關(guān)算法C+實(shí)現(xiàn)一、堆棧.cpp部分#include<iostream>#include"stack.h"using namespace std;int main () int c; cout<<"輸入堆棧大小:"<<endl; cin>>c;astack<int> STA1(c); int t; cout<<"輸入棧元素:"<<endl;for(int i=0;i<c;i+) cin>>
2、;t;STA1.push(t); int ch;cout<<"1:彈棧"<<endl;cout<<"2:獲取棧頂元素:"<<endl;cout<<"3:入棧元素:"<<endl;cout<<"4:輸出棧中元素;"<<endl;cout<<"5:重設(shè)棧的大小:"<<endl;cin>>ch;while(ch!=-1)switch(ch)case 1:int re1;
3、STA1.pop(re1); cout<<"刪除棧頂元素:"<<re1<<endl; break;case 2:int re2 ; STA1.peek(re2); cout<<"獲取棧頂元素:"<<re2<<endl; break;case 3:int r; cout<<"輸入入棧元素:"<<endl; cin>>r; STA1.push(r); break;case 4:STA1.print();break;case 5:in
4、t s; cout<<"輸入新的大小:"<<endl; cin>>s; STA1.setsize(s); break;cout<<"還需要什么幫助嗎?"<<endl;cin>>ch;if(ch=-1)cout<<"謝謝使用"<<endl;return 0;.h部分#include<iostream>template<class T>class astack /順序堆棧/private:int size;T * sta
5、ckarray;int top;int maxstacksize;public:astack(int s )maxstacksize=100;size=s;stackarray=new T maxstacksize;top=-1;astack()delete stackarray;bool push(const T& item)if(isfull() cout<<"棧滿!"<<endl;return false;stackarray+top=item;return true;bool pop( T &item)if(isempty()
6、cout<<"???"<<endl;return false;item =stackarraytop-;return true;bool peek(T &item)constif(isempty()cout<<"???"<<endl;return false;item=stackarraytop;return true;int isempty(void)constreturn top=-1;int isfull(void)constreturn top=size-1;void clear(void)
7、top=-1;void print();void setsize(int s)size=s;template<class T>void astack<T>:print()for(int i=0;i<size;i+)cout<<stackarrayi<<" "二、隊(duì)列.cpp部分#include<iostream>#include"queue.h"using namespace std;int main () linkqueue<int> que1;cout<<&qu
8、ot;輸入隊(duì)列大小:"<<endl;int s;cin>>s;cout<<"輸入元素:"<<endl;int c;for(int i=0;i<s;i+)cin>>c;que1.qinsert(c);int ch;cout<<"1:刪除元素:"<<endl;cout<<"2:輸出隊(duì)首元素:"<<endl;cout<<"3:輸出隊(duì)列元素:"<<endl;cout<&l
9、t;"4:插入元素:"<<endl;cin>>ch;while(ch!=-1)switch(ch)case 1:int re1; cout<<"已刪除元素:"<< que1.qdelete(re1)<<endl; break;case 2:int re2; que1.qget(re2); cout<<"隊(duì)首元素:"<<re2<<endl; break;case 3:que1.print();break;case 4:int temp; co
10、ut<<"輸入元素:"<<endl; cin>>temp; que1.qinsert(temp); break;cout<<"還需要什么幫助嗎?"<<endl;cin>>ch;if(ch=-1)cout<<"謝謝使用"<<endl;return 0;.h部分#include<iostream>template< class T>struct SLNodeT data;SLNode <T> * next;S
11、LNode( SLNode * nextnode=NULL)next=nextnode;SLNode(const T& item , SLNode * nextnode=NULL)data=item; next=nextnode;template<class T>class linkqueue/ 鏈?zhǔn)疥?duì)列/private:SLNode<T> * front, * rear;int count;public:linkqueue()front=NULL;rear=NULL;linkqueue()qclear();void qinsert(const T &
12、item);bool qdelete(T & item); bool qget(T& item);int isempty()constreturn front=NULL;void qclear();void print();template<class T>void linkqueue<T>:qinsert(const T&item)if(isempty()front=rear=new SLNode<T>(item,NULL);count=1;else rear->next=new SLNode<T>(item,NU
13、LL);rear=rear->next;count+;template <class T>bool linkqueue<T>: qdelete(T& item)if(isempty()cout<<"隊(duì)列為空!"<<endl;return false;SLNode <T>* temp=front;item=front->data;front=front->next;count-; delete temp;if(count=0)rear=NULL;return true;template &l
14、t;class T>bool linkqueue< T>: qget(T& item)if(isempty()cout<<"隊(duì)列為空!"<<endl;return false; item=front->data;return true;template <class T>void linkqueue<T>:qclear()while(!isempty()rear=front;front=front->next;delete rear;count-;rear=NULL;template<
15、;class T>void linkqueue<T>:print() SLNode<T> * p=front; while(p->next!=NULL) cout<<p->data<<" " p=p->next; cout<<p->data<<endl;三、字符串匹配.cpp部分#include<iostream>#include"Choice.h"using namespace std;int main ()char re;SLList&l
16、t;char> list;cout<<"輸入待檢測(cè)算式:"<<endl;cin>>re;while(re!='#')list.add(re);cin>>re; list.listout();check(list);return 0;.h部分#include<iostream>template<class T>struct SLNodeT data;SLNode <T> * next;SLNode( SLNode * nextnode=NULL)next=nextnode
17、;SLNode(const T& item , SLNode * nextnode=NULL)data=item; next=nextnode;template<class T>class SLList private: SLNode<T> * head, *tail ,*guard; int size; public: SLList(); SLList(T& item); SLList(); bool isempty()return head->next=NULL; int lenth(); void add(T& item); bool
18、 get(int k, T& item); void listout(); void match();template<class T>SLList<T>:SLList()head=tail=guard=new SLNode<T>();size=0;template<class T>SLList<T>:SLList(T& item) tail=guard=new SLNode<T>(item,NULL);head=new SLNode<T>(guard);size=1;template<c
19、lass T>SLList<T>:SLList()while(!isempty()guard=head; head=guard->next;delete guard;delete head;template<class T>int SLList<T>:lenth()return size;template<class T>void SLList<T>:add(T& item) tail->next=new SLNode<T> (item,tail->next); tail=tail->
20、next; size+;template<class T>void SLList<T>:listout()if(isempty()cout<<"鏈表空!"<<endl;elsecout<<"鏈表大小:"<<size<<endl; int i=0;guard=head->next;while(guard->next!=NULL)cout<<"第"<<i<<"個(gè)元素是:"<<g
21、uard->data<<endl;guard=guard->next;i+;cout<<"第"<<i<<"個(gè)元素是:"<<guard->data<<endl;template<class T>void SLList<T>:match()char s150;char s250;int i=0, j=0;int rei ,rej; guard=head;while(guard->next!=NULL)if(guard->data=''|guard->data=''|guard->data='(')s1i=guard->data;i+; guard=guard->next;else if(guard->data=''|guard->data=
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(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ì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 2025年供水設(shè)施建設(shè)協(xié)議書
- 2025年緊急出口門采購合同
- 2025年午休時(shí)段兒童看護(hù)服務(wù)協(xié)議
- 兒童領(lǐng)養(yǎng)程序指導(dǎo)協(xié)議
- 2025年產(chǎn)品市場(chǎng)分隔協(xié)議范本
- 2025年防水建材項(xiàng)目立項(xiàng)申請(qǐng)報(bào)告模板
- 2025年公共場(chǎng)所消防設(shè)施供應(yīng)及維護(hù)合同
- 2025年同心同行策劃合作框架協(xié)議
- 2025年醫(yī)療用品分銷合作伙伴協(xié)議范例
- 2025年共同策劃長遠(yuǎn)發(fā)展協(xié)同計(jì)劃協(xié)議書標(biāo)準(zhǔn)樣式
- DL-T 2574-2022 混流式水輪機(jī)維護(hù)檢修規(guī)程
- 《鋼鐵是怎樣煉成的》讀書分享課件
- 思想旗領(lǐng)航向心得體會(huì)
- 計(jì)算機(jī)軟件確認(rèn)控制程序
- 造價(jià)員安全生產(chǎn)責(zé)任制
- 橋梁樁基專項(xiàng)施工方案-
- 高中生物競(jìng)賽課件 【知識(shí)精研+拓展提升】 細(xì)胞生物學(xué)
- 農(nóng)產(chǎn)品食品檢驗(yàn)員二級(jí)技師職業(yè)技能鑒定考試題庫(含答案)
- 工廠車間劃線標(biāo)準(zhǔn)與標(biāo)識(shí)管理(共37張PPT)
- 完整版人教版PEP英語四年級(jí)下冊(cè)全冊(cè)課件ppt
- 水利工程建設(shè)管理概述課件
評(píng)論
0/150
提交評(píng)論