欢迎来到天天文库
浏览记录
ID:13562943
大小:49.50 KB
页数:17页
时间:2018-07-23
《堆栈队列字符串匹配相关算法实现》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
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<<"删除栈顶元素:"<3、"输入入栈元素:"<>r;STA1.push(r);break;}case4:{STA1.print();break;}case5:{ints;cout<<"输入新的大小:"<>s;STA1.setsize(s);break;}}cout<<"还需要什么帮助吗?"<>ch;}if(ch==-1)cout<<"谢谢使用"<templateclassastac4、k{//顺序堆栈//private:intsize;T*stackarray;inttop;intmaxstacksize;public:astack(ints){maxstacksize=100;size=s;stackarray=newT[maxstacksize];top=-1;}~astack(){delete[]stackarray;}boolpush(constT&item){if(isfull()){cout<<"栈满!"<5、op]=item;returntrue;}boolpop(T&item){if(isempty()){cout<<"栈空!"<6、intisfull(void)const{returntop==size-1;}voidclear(void){top=-1;}voidprint();voidsetsize(ints){size=s;}};templatevoidastack::print(){for(inti=0;i#include"queue.h"usingnamespacestd;i7、ntmain(){linkqueueque1;cout<<"输入队列大小:"<>s;cout<<"输入元素:"<>c;que1.qinsert(c);}intch;cout<<"1:删除元素:"<>ch;while(ch!=-1){swi8、tch(ch){case1:{intre1;cout<<"已删除元素:"<>temp;que1.qinsert(temp);b
2、"<>ch;while(ch!=-1){switch(ch){case1:{intre1;STA1.pop(re1);cout<<"删除栈顶元素:"<3、"输入入栈元素:"<>r;STA1.push(r);break;}case4:{STA1.print();break;}case5:{ints;cout<<"输入新的大小:"<>s;STA1.setsize(s);break;}}cout<<"还需要什么帮助吗?"<>ch;}if(ch==-1)cout<<"谢谢使用"<templateclassastac4、k{//顺序堆栈//private:intsize;T*stackarray;inttop;intmaxstacksize;public:astack(ints){maxstacksize=100;size=s;stackarray=newT[maxstacksize];top=-1;}~astack(){delete[]stackarray;}boolpush(constT&item){if(isfull()){cout<<"栈满!"<5、op]=item;returntrue;}boolpop(T&item){if(isempty()){cout<<"栈空!"<6、intisfull(void)const{returntop==size-1;}voidclear(void){top=-1;}voidprint();voidsetsize(ints){size=s;}};templatevoidastack::print(){for(inti=0;i#include"queue.h"usingnamespacestd;i7、ntmain(){linkqueueque1;cout<<"输入队列大小:"<>s;cout<<"输入元素:"<>c;que1.qinsert(c);}intch;cout<<"1:删除元素:"<>ch;while(ch!=-1){swi8、tch(ch){case1:{intre1;cout<<"已删除元素:"<>temp;que1.qinsert(temp);b
3、"输入入栈元素:"<>r;STA1.push(r);break;}case4:{STA1.print();break;}case5:{ints;cout<<"输入新的大小:"<>s;STA1.setsize(s);break;}}cout<<"还需要什么帮助吗?"<>ch;}if(ch==-1)cout<<"谢谢使用"<templateclassastac
4、k{//顺序堆栈//private:intsize;T*stackarray;inttop;intmaxstacksize;public:astack(ints){maxstacksize=100;size=s;stackarray=newT[maxstacksize];top=-1;}~astack(){delete[]stackarray;}boolpush(constT&item){if(isfull()){cout<<"栈满!"<5、op]=item;returntrue;}boolpop(T&item){if(isempty()){cout<<"栈空!"<6、intisfull(void)const{returntop==size-1;}voidclear(void){top=-1;}voidprint();voidsetsize(ints){size=s;}};templatevoidastack::print(){for(inti=0;i#include"queue.h"usingnamespacestd;i7、ntmain(){linkqueueque1;cout<<"输入队列大小:"<>s;cout<<"输入元素:"<>c;que1.qinsert(c);}intch;cout<<"1:删除元素:"<>ch;while(ch!=-1){swi8、tch(ch){case1:{intre1;cout<<"已删除元素:"<>temp;que1.qinsert(temp);b
5、op]=item;returntrue;}boolpop(T&item){if(isempty()){cout<<"栈空!"<6、intisfull(void)const{returntop==size-1;}voidclear(void){top=-1;}voidprint();voidsetsize(ints){size=s;}};templatevoidastack::print(){for(inti=0;i#include"queue.h"usingnamespacestd;i7、ntmain(){linkqueueque1;cout<<"输入队列大小:"<>s;cout<<"输入元素:"<>c;que1.qinsert(c);}intch;cout<<"1:删除元素:"<>ch;while(ch!=-1){swi8、tch(ch){case1:{intre1;cout<<"已删除元素:"<>temp;que1.qinsert(temp);b
6、intisfull(void)const{returntop==size-1;}voidclear(void){top=-1;}voidprint();voidsetsize(ints){size=s;}};templatevoidastack::print(){for(inti=0;i#include"queue.h"usingnamespacestd;i
7、ntmain(){linkqueueque1;cout<<"输入队列大小:"<>s;cout<<"输入元素:"<>c;que1.qinsert(c);}intch;cout<<"1:删除元素:"<>ch;while(ch!=-1){swi
8、tch(ch){case1:{intre1;cout<<"已删除元素:"<>temp;que1.qinsert(temp);b
此文档下载收益归作者所有