堆栈队列字符串匹配相关算法实现

上传人:wt****50 文档编号:33997829 上传时间:2018-02-19 格式:DOC 页数:17 大小:49.50KB
返回 下载 相关 举报
堆栈队列字符串匹配相关算法实现_第1页
第1页 / 共17页
堆栈队列字符串匹配相关算法实现_第2页
第2页 / 共17页
堆栈队列字符串匹配相关算法实现_第3页
第3页 / 共17页
堆栈队列字符串匹配相关算法实现_第4页
第4页 / 共17页
堆栈队列字符串匹配相关算法实现_第5页
第5页 / 共17页
点击查看更多>>
资源描述

《堆栈队列字符串匹配相关算法实现》由会员分享,可在线阅读,更多相关《堆栈队列字符串匹配相关算法实现(17页珍藏版)》请在金锄头文库上搜索。

1、堆栈、队列、字符串匹配相关算法 C+实现一、堆栈.cpp 部分#include#includestack.husing namespace std;int main ()int c;coutc;astack STA1(c);int t;coutt;STA1.push(t);int ch;coutch;while(ch!=-1)switch(ch)case 1:int re1;STA1.pop(re1);coutr;STA1.push(r);break;case 4:STA1.print();break;case 5:int s;couts;STA1.setsize(s); break;cout

2、ch;if(ch=-1)couttemplateclass astack /顺序堆栈/private:int size;T * stackarray;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() coutvoid astack:print()for(int i=0;i#includequeue.husing

3、 namespace std;int main () linkqueue que1;couts;coutc;que1.qinsert(c);int ch;coutch;while(ch!=-1)switch(ch)case 1:int re1;couttemp;que1.qinsert(temp);break;coutch;if(ch=-1)couttemplatestruct SLNodeT data;SLNode * next;SLNode( SLNode * nextnode=NULL)next=nextnode;SLNode(const T& item , SLNode * nextn

4、ode=NULL)data=item; next=nextnode;templateclass linkqueue/ 链式队列/private:SLNode * front, * rear;int count;public:linkqueue()front=NULL;rear=NULL;linkqueue()qclear();void qinsert(const T bool qdelete(T int isempty()constreturn front=NULL;void qclear();void print();templatevoid linkqueue:qinsert(const

5、T&item)if(isempty()front=rear=new SLNode(item,NULL);count=1;else rear-next=new SLNode(item,NULL);rear=rear-next;count+;template bool linkqueue: qdelete(T& item)if(isempty()cout* temp=front;item=front-data;front=front-next;count-;delete temp;if(count=0)rear=NULL;return true;template bool linkqueue: q

6、get(T& item)if(isempty()coutdata;return true;template void linkqueue:qclear()while(!isempty()rear=front;front=front-next;delete rear;count-;rear=NULL;templatevoid linkqueue:print()SLNode * p=front;while(p-next!=NULL)coutdatanext;coutdata#includeChoice.husing namespace std;int main ()char re;SLList l

7、ist;coutre;while(re!=#)list.add(re);cinre;list.listout();check(list);return 0;.h 部分#includetemplatestruct SLNodeT data;SLNode * next;SLNode( SLNode * nextnode=NULL)next=nextnode;SLNode(const T next=nextnode;templateclass SLListprivate:SLNode * head, *tail ,*guard;int size;public:SLList();SLList(TSLL

8、ist();bool isempty()return head-next=NULL;int lenth();void add(Tbool get(int k, Tvoid listout();void match();templateSLList:SLList()head=tail=guard=new SLNode();size=0;templateSLList:SLList(T& item)tail=guard=new SLNode(item,NULL);head=new SLNode(guard);size=1;templateSLList:SLList()while(!isempty()

9、guard=head;head=guard-next;delete guard;delete head;templateint SLList:lenth()return size;templatevoid SLList:add(T& item)tail-next=new SLNode (item,tail-next);tail=tail-next; size+;templatevoid SLList:listout()if(isempty()coutnext;while(guard-next!=NULL)coutdatanext;i+;coutdatavoid SLList:match()ch

10、ar 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=|guard-data=)s2j=guard-data;j+;guard=guard-next;else guard=guard-next;if(guard-data=|guard-data=|guard-data=()s1i=guard-data;i+;if(guard-data=|guard-data=|guard-data=)s2j=guard-data;j+;rei=i;rej=j;int count=0;for(i=0,j=rej-1;i=0;)if(s1i=(&s2j=)|(s1i=&s2j=)|(s1i=&s2j=)i+;j-;count+;if(count=reielse coutvoid check(SLList & list)list.match();

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 生活休闲 > 社会民生

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号