堆栈队列字符串匹配相关算法实现Word格式.doc

上传人:wj 文档编号:1455259 上传时间:2023-04-30 格式:DOC 页数:17 大小:29.50KB
下载 相关 举报
堆栈队列字符串匹配相关算法实现Word格式.doc_第1页
第1页 / 共17页
堆栈队列字符串匹配相关算法实现Word格式.doc_第2页
第2页 / 共17页
堆栈队列字符串匹配相关算法实现Word格式.doc_第3页
第3页 / 共17页
堆栈队列字符串匹配相关算法实现Word格式.doc_第4页
第4页 / 共17页
堆栈队列字符串匹配相关算法实现Word格式.doc_第5页
第5页 / 共17页
堆栈队列字符串匹配相关算法实现Word格式.doc_第6页
第6页 / 共17页
堆栈队列字符串匹配相关算法实现Word格式.doc_第7页
第7页 / 共17页
堆栈队列字符串匹配相关算法实现Word格式.doc_第8页
第8页 / 共17页
堆栈队列字符串匹配相关算法实现Word格式.doc_第9页
第9页 / 共17页
堆栈队列字符串匹配相关算法实现Word格式.doc_第10页
第10页 / 共17页
堆栈队列字符串匹配相关算法实现Word格式.doc_第11页
第11页 / 共17页
堆栈队列字符串匹配相关算法实现Word格式.doc_第12页
第12页 / 共17页
堆栈队列字符串匹配相关算法实现Word格式.doc_第13页
第13页 / 共17页
堆栈队列字符串匹配相关算法实现Word格式.doc_第14页
第14页 / 共17页
堆栈队列字符串匹配相关算法实现Word格式.doc_第15页
第15页 / 共17页
堆栈队列字符串匹配相关算法实现Word格式.doc_第16页
第16页 / 共17页
堆栈队列字符串匹配相关算法实现Word格式.doc_第17页
第17页 / 共17页
亲,该文档总共17页,全部预览完了,如果喜欢就下载吧!
下载资源
资源描述

堆栈队列字符串匹配相关算法实现Word格式.doc

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

堆栈队列字符串匹配相关算法实现Word格式.doc

获取栈顶元素:

3:

入栈元素:

4:

输出栈中元素;

5:

重设栈的大小:

cin>

ch;

while(ch!

=-1){

switch(ch){

case1:

{intre1;

STA1.pop(re1);

cout<

删除栈顶元素:

re1<

break;

}

case2:

{intre2;

STA1.peek(re2);

re2<

case3:

{intr;

输入入栈元素:

cin>

r;

STA1.push(r);

case4:

{STA1.print();

break;

case5:

{ints;

输入新的大小:

s;

STA1.setsize(s);

}

cout<

还需要什么帮助吗?

cin>

}

if(ch==-1)cout<

谢谢使用"

return0;

.h部分

template<

classT>

classastack{//顺序堆栈//

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<

栈满!

returnfalse;

}

stackarray[++top]=item;

returntrue;

boolpop(T&

item){

if(isempty()){

栈空!

item=stackarray[top--];

boolpeek(T&

item)const{

returnfalse;

item=stackarray[top];

intisempty(void)const{returntop==-1;

intisfull(void)const{returntop==size-1;

voidclear(void){top=-1;

voidprint();

voidsetsize(ints){size=s;

};

voidastack<

T>

:

print(){

size;

i++)cout<

stackarray[i]<

"

;

二、队列

queue.h"

linkqueue<

que1;

输入队列大小:

ints;

输入元素:

intc;

que1.qinsert(c);

intch;

删除元素:

输出队首元素:

输出队列元素:

插入元素:

cout<

已删除元素:

que1.qdelete(re1)<

break;

{intre2;

que1.qget(re2);

cout<

队首元素:

break;

{que1.print();

break;

{inttemp;

temp;

que1.qinsert(temp);

classT>

structSLNode{

Tdata;

SLNode<

*next;

SLNode(SLNode*nextnode=NULL){

next=nextnode;

SLNode(constT&

item,SLNode*nextnode=NULL){

data=item;

next=nextnode;

classlinkqueue{//链式队列//

private:

SLNode<

*front,*rear;

intcount;

public:

linkqueue(){front=NULL;

rear=NULL;

~linkqueue(){qclear();

voidqinsert(constT&

item);

boolqdelete(T&

boolqget(T&

intisempty()const{returnfront==NULL;

voidqclear();

voidprint();

voidlinkqueue<

qinsert(constT&

if(isempty()){

front=rear=newSLNode<

(item,NULL);

count=1;

else{

rear->

next=newSLNode<

rear=rear->

next;

count++;

template<

boollinkqueue<

qdelete(T&

队列为空!

returnfalse;

*temp=front;

item=front->

data;

front=front->

count--;

deletetemp;

if(count==0)rear=NULL;

returntrue;

T>

qget(T&

item=front->

qclear(){

while(!

isempty()){

rear=front;

front=front->

deleterear;

count--;

rear=NULL;

SLNode<

*p=front;

while(p->

next!

=NULL){

cout<

p->

data<

p=p->

}

cout<

三、字符串匹配

Choice.h"

charre;

SLList<

char>

list;

输入待检测算式:

re;

while(re!

='

#'

){

list.add(re);

list.listout();

check(list);

SLNode(SLNode*nextnode=NULL){next=nextnode;

item,SLNode*nextnode=NULL){data=item;

classSLList{

private:

SLNode<

*head,*tail,*guard;

intsize;

public:

SLList();

SLList(T&

~SLList();

boolisempty(){returnhead->

next==NULL;

intlenth();

voidadd(T&

boolget(intk,T&

voidlistout();

voidmatch();

SLList<

SLList(){

head=tail=guard=newSLNode<

();

size=0;

SLList(T&

tail=guard=newSLNode<

head=newSLNode<

(guard);

size=1;

~SLList(){

guard=head;

head=guard->

deleteguard;

deletehead;

intSLList<

lenth(){

returnsize;

voidSLList<

add(T&

tail->

(item,tail->

next);

tail=tail->

size++;

listout(){

if(isempty()){cout<

链表空!

else{cout<

链表大小:

size<

inti=0;

guard=head->

while(guard->

第"

个元素是:

guard->

guard=guard->

i++;

match(){

chars1[50];

chars2[50];

inti=0,j=0;

intrei,rej;

guard=head;

if(guard->

data=='

{'

||guard->

['

('

s1[i]=guard->

i++;

guard=guard->

elseif(guard->

}'

]'

)'

s2[j]=guard->

j++;

guard=guard->

elseguard=guard->

if(guard->

rei=i;

rej=j;

intcount=0;

for(i=0,j=rej-1;

rei,j>

=0;

if((s1[i]=='

&

s2[j]=='

)||(s1[i]=='

)){

i++;

j--;

count++;

}

if(count==rei&

count==rej)cout<

符号匹配!

elsecout<

符号不匹配!

voidcheck(SLList<

&

list){

list.match();

展开阅读全文
相关资源
猜你喜欢
相关搜索
资源标签

当前位置:首页 > PPT模板 > 商务科技

copyright@ 2008-2023 冰点文库 网站版权所有

经营许可证编号:鄂ICP备19020893号-2