数据结构课件2第3_5章作业.ppt

数据结构课件2第3_5章作业.ppt

ID:48185354

大小:99.50 KB

页数:16页

时间:2020-01-16

数据结构课件2第3_5章作业.ppt_第1页
数据结构课件2第3_5章作业.ppt_第2页
数据结构课件2第3_5章作业.ppt_第3页
数据结构课件2第3_5章作业.ppt_第4页
数据结构课件2第3_5章作业.ppt_第5页
资源描述:

《数据结构课件2第3_5章作业.ppt》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库

1、【3.15】#defineSTACKSIZE50#defineSTACKINCREMENT10typedefstrcutDStack{ElemType*elem;inttop1,top2;intstacksize;}DStack;StatusInitStack(DStack&S){if(!S.elem=newElemType[STACKSIZE])exit(OVERFLOW);S.stacksize=STACKSIZE;S.top1=0;S.top2=STACKSIZE-1;returnOK;}top1top2elemStatusPush(DStack&S,inti,ElemTypex

2、){if(i!=0&&i!=1)returnERROR;if(S.top1>S.top2){newbase=realloc(S.elem,stacksize,STACKINCREMENT);if(!newbase)exit(OVERFLOW);if(S.elem)delete[]S.elem;S.elem=newbase;for(j=S.stacksize-1;j>S.top2;j--)S.elem[j+STACKINCREMENT]=S.elem[j];S.stacksize+=STACKINCREMENT;S.top2+=SATCKINCREMENT;}if(i==0){S.ele

3、m[top1++]=x;}else{S.elem[top2--]=x;}returnOK;}top1top2elemStatusPop(DStack&S,inti,ElemType&e){if(i!=0&&1!=1)returnERROR;if(i==0){if(S.top1==0)returnERROR;e=S.elem[--S.top1];}else{if(S.top2==S.stacksize-1)returnERROR;e=S.elem[++S.top2];}returnOK;}【3.17】intIsSymmetry(){InitStack(S);cin>>ch;while(c

4、h!='@'&&ch!='&'){push(S,ch);cin>>ch;}if(ch=='&'){cin>>ch;while(ch!='@'){if(StackEmpty(S))returnFLASE;Pop(S,e);if(ch!=e)returnFLASE;cin>>ch;}}if(ch=='@'&&!StackEmpty(S))returnFLASE;returnTRUE;}【3.21】StatusreversePolistnotion(charexp[],charrPolist[]){//表达式以'#'结束InitStack(S);i=0;k=0;while(exp[i]!='

5、#'

6、

7、!StackEmpty(S)){switch(exp[i]){(isvariable):rPolist[k++]=exp[i++];break;(isoperator)

8、

9、(is'#'):GetTop(S,e);while(!StackEmpty(S)&&comp(e>=exp[i]){Pop(S,rPolist[k++]);GetTop(S,e);}if(exp[i]!=’#’)Push(S,exp[i++]);break;}}rPolist[k]='#';returnOK;}【3.22】Statuscalculate(charrPolist[]){InitStack(S);

10、for(i=0;rPolist[i]!='#';i++){if(rPolist[i]isvariable)Push(S,rPolist[i]);else{Pop(S,p2);Pop(S,p1);Push(S,operate(p1,rPolist,p2));}}}【3.27(1)】intakm((intm,intn){if(m==0)returnn+1;elseif(n==0)returnakm(m-1,1);else{t=akm(m,n-1);returnakm(m-1,t);}}注意:不能给函数名赋值【3.28】typedefstructNode{ElemTypedata;struc

11、tNode*next;}NODE,StatutsInitQueue(QUEUE&Q){Q.rear=newNODE;if(!Q.rear)returnOVERFLOW;Q.rear->next=Q.rear;returnOK;}typedefstructQueue{Node*rear;}QUEUE;StatutsEnQueue(QUEUE&Q,ElemTypee){s=newNODE;if(!s)returnOVERFLOW;s->data=e

当前文档最多预览五页,下载文档查看全文

此文档下载收益归作者所有

当前文档最多预览五页,下载文档查看全文
温馨提示:
1. 部分包含数学公式或PPT动画的文件,查看预览时可能会显示错乱或异常,文件下载后无此问题,请放心下载。
2. 本文档由用户上传,版权归属用户,天天文库负责整理代发布。如果您对本文档版权有争议请及时联系客服。
3. 下载前请仔细阅读文档内容,确认文档内容符合您的需求后进行下载,若出现内容与标题不符可向本站投诉处理。
4. 下载文档时可能由于网络波动等原因无法下载或下载错误,付费完成后未能成功下载的用户请联系客服处理。