欢迎来到天天文库
浏览记录
ID:18438728
大小:49.50 KB
页数:17页
时间:2018-09-17
《堆栈队列字符串匹配相关算法实现》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、堆栈、队列、字符串匹配相关算法C++实现一、堆栈.cpp部分#include#include"stack.h"usingnamespacestd;intmain(){intc;cout<<"输入堆栈大小:"<>c;astackSTA1(c);intt;cout<<"输入栈元素:"<>t;STA1.push(t);}intch;cout<<"1:弹栈"<2、中元素;"<>ch;while(ch!=-1){switch(ch){case1:{intre1;STA1.pop(re1);cout<<"删除栈顶元素:"<>r;STA1.push(r);break;}case4:{STA1.print();break;}case5:{ints;co3、ut<<"输入新的大小:"<>s;STA1.setsize(s);break;}}cout<<"还需要什么帮助吗?"<>ch;}if(ch==-1)cout<<"谢谢使用"<templateclassastack{//顺序堆栈//private:intsize;T*stackarray;inttop;intmaxstacksize;public:astack(ints){maxstacksize=100;size=s;stackarray=newT[maxs4、tacksize];top=-1;}~astack(){delete[]stackarray;}boolpush(constT&item){if(isfull()){cout<<"栈满!"<5、dl;returnfalse;}item=stackarray[top];returntrue;}intisempty(void)const{returntop==-1;}intisfull(void)const{returntop==size-1;}voidclear(void){top=-1;}voidprint();voidsetsize(ints){size=s;}};templatevoidastack::print(){for(inti=0;i6、ostream>#include"queue.h"usingnamespacestd;intmain(){linkqueueque1;cout<<"输入队列大小:"<>s;cout<<"输入元素:"<>c;que1.qinsert(c);}intch;cout<<"1:删除元素:"<>ch;while(ch!=-1){s7、witch(ch){case1:{intre1;cout<<"已删除元素:"<>temp;que1.qinsert(temp);b
2、中元素;"<>ch;while(ch!=-1){switch(ch){case1:{intre1;STA1.pop(re1);cout<<"删除栈顶元素:"<>r;STA1.push(r);break;}case4:{STA1.print();break;}case5:{ints;co
3、ut<<"输入新的大小:"<>s;STA1.setsize(s);break;}}cout<<"还需要什么帮助吗?"<>ch;}if(ch==-1)cout<<"谢谢使用"<templateclassastack{//顺序堆栈//private:intsize;T*stackarray;inttop;intmaxstacksize;public:astack(ints){maxstacksize=100;size=s;stackarray=newT[maxs
4、tacksize];top=-1;}~astack(){delete[]stackarray;}boolpush(constT&item){if(isfull()){cout<<"栈满!"<5、dl;returnfalse;}item=stackarray[top];returntrue;}intisempty(void)const{returntop==-1;}intisfull(void)const{returntop==size-1;}voidclear(void){top=-1;}voidprint();voidsetsize(ints){size=s;}};templatevoidastack::print(){for(inti=0;i6、ostream>#include"queue.h"usingnamespacestd;intmain(){linkqueueque1;cout<<"输入队列大小:"<>s;cout<<"输入元素:"<>c;que1.qinsert(c);}intch;cout<<"1:删除元素:"<>ch;while(ch!=-1){s7、witch(ch){case1:{intre1;cout<<"已删除元素:"<>temp;que1.qinsert(temp);b
5、dl;returnfalse;}item=stackarray[top];returntrue;}intisempty(void)const{returntop==-1;}intisfull(void)const{returntop==size-1;}voidclear(void){top=-1;}voidprint();voidsetsize(ints){size=s;}};templatevoidastack::print(){for(inti=0;i6、ostream>#include"queue.h"usingnamespacestd;intmain(){linkqueueque1;cout<<"输入队列大小:"<>s;cout<<"输入元素:"<>c;que1.qinsert(c);}intch;cout<<"1:删除元素:"<>ch;while(ch!=-1){s7、witch(ch){case1:{intre1;cout<<"已删除元素:"<>temp;que1.qinsert(temp);b
6、ostream>#include"queue.h"usingnamespacestd;intmain(){linkqueueque1;cout<<"输入队列大小:"<>s;cout<<"输入元素:"<>c;que1.qinsert(c);}intch;cout<<"1:删除元素:"<>ch;while(ch!=-1){s
7、witch(ch){case1:{intre1;cout<<"已删除元素:"<>temp;que1.qinsert(temp);b
此文档下载收益归作者所有