数据结构习题集答案(C语言版严蔚敏)(10)
}
void RegionFilling(ElemType g[M][N],PosType CurPos,int FillColor) {
if(CurPos.x Push(s,g[CurPos.x][CurPos.y+1]); !g[CurPos.x][CurPos.y-1].Visited && g[CurPos.x][CurPos.y-1].Color==OldColor if(CurPos.y>0 && Push(s,g[CurPos.x-1][CurPos.y]); !g[CurPos.x][CurPos.y+1].Visited && g[CurPos.x][CurPos.y+1].Color==OldColor if(CurPos.y Push(s,g[CurPos.x+1][CurPos.y]); !g[CurPos.x-1][CurPos.y].Visited && g[CurPos.x-1][CurPos.y].Color==OldColor if(CurPos.x>0 && !g[CurPos.x+1][CurPos.y].Visited && g[CurPos.x+1][CurPos.y].Color==OldColor Stack s; InitStack(s); ElemType e; int OldColor=g[CurPos.x][CurPos.y].Color; Push(s,g[CurPos.x][CurPos.y]); while(!StackEmpty(s)){ Pop(s,e); CurPos=e.seat; g[CurPos.x][CurPos.y].Color=FillColor; g[CurPos.x][CurPos.y].Visited=1; PosType StartPos; StartPos.x=5; StartPos.y=5; int FillColor=6; RegionFilling(g,StartPos,FillColor); cout< ShowGraphArray(g); } void CreateGDS(ElemType g[M][N]) { } void ShowGraphArray(ElemType g[M][N]) { } 3.21 假设表达式有单字母变量和双目四则运算符构成。试写一个算法,将一个通常书写形式且书写正确的表达式转换为逆波兰表达式。 解: // 输入的表达式串必须为#...#格式 void InversePolandExpression(char Buffer[]) { Push(s,Buffer[i]); Stack s; InitStack(s); int i=0,j=0; ElemType e; int i,j; for(i=0;i for(j=0;j cout< for(i=0;i for(j=0;j for(j=2;j<4;j++) g[i][j].Color=3; g[i][j].seat.x=i; g[i][j].seat.y=j; g[i][j].Visited=0; g[i][j].Color=0; } ) Push(s,g[CurPos.x][CurPos.y-1]); for(i=2;i<5;i++) for(i=5;i for(j=3;j<6;j++) g[i][j].Color=3; } Status IsOpertor(char c) { } Status Prior(char c1,char c2) { char ch[]=\int i=0,j=0; while(ch[i] && ch[i]!=c1) i++; if(i==2) i--; // 加和减可认为是同级别的运算符 char *p=\while(*p){ } return FALSE; if(*p==c) return TRUE; p++; i++; while(Buffer[i]!='#'){ } while(!StackEmpty(s)){ } Pop(s,e); Buffer[j]=e; j++; if(!IsOperator(Buffer[i])){ // 是操作数 } else{ // 是操作符 } GetTop(s,e); if(Prior(e,Buffer[i])){// 当栈顶优先权高于当前序列时,退栈 } else{ } Push(s,Buffer[i]); i++; Pop(s,e); Buffer[j]=e; j++; Buffer[j]=Buffer[i]; i++; j++; } 3.22 如题3.21的假设条件,试写一个算法,对以逆波兰式表示的表达式求值。 解: char CalVal_InverPoland(char Buffer[]) { } char Cal(char c1,char op,char c2) { ch[0]=c2; ch[1]='\\0'; x2=atoi(ch); int x,x1,x2; char ch[10]; ch[0]=c1; ch[1]='\\0'; x1=atoi(ch); while(Buffer[i]!='#'){ } return c; if(!IsOperator(Buffer[i])){ } else{ } i++; Pop(Opnd,e2); Pop(Opnd,e1); c=Cal(e1,Buffer[i],e2); Push(Opnd,c); Push(Opnd,Buffer[i]); Stack Opnd; InitStack(Opnd); int i=0; char c; ElemType e1,e2; if(i==4) i--; if(j==2) j--; if(j==4) j--; if(i>=j) return TRUE; else return FALSE; // 乘和除可认为是同级别的运算符 while(ch[j] && ch[j]!=c2) j++; } 3.23 如题3.21的假设条件,试写一个算法,判断给定的非空后缀表达式是否为正确的逆波兰表达式,如果是,则将它转化为波兰式。 解: #include #include \ typedef char ARRAY[30]; typedef ARRAY ElemType; typedef struct NodeType{ ElemType data; NodeType *next; switch(op){ case '+': } itoa(x,ch,10); return ch[0]; x=x1+x2; break; x=x1-x2; break; x=x1*x2; break; x=x1/x2; break; break; case '-': case '*': case '/': default: }NodeType,*LinkType; typedef struct{ void InitStack(Stack &s); Status Push(Stack &s,ElemType e); Status Pop(Stack &s,ElemType e); Status IsOperator(char c); Status StackEmpty(Stack s); LinkType top; int size; }Stack;
相关推荐:
- [综合文档]应答器设备技术规范(征求意见稿)A1
- [综合文档]教师 2012年高考政治试题按考点分类汇
- [综合文档]保险公司的总经理助理竞职演说
- [综合文档]卫生应急大练兵大比武活动考试--题库(
- [综合文档]徐州经济技术开发区总体规划环境影响报
- [综合文档]汉语拼音表(带声调)
- [综合文档]二年级 上 思维训练( 1~18)
- [综合文档]特色学校五年发展规划
- [综合文档]机床经常出现报警“X1轴定位监控”
- [综合文档]《电子技术基础》21.§5—2、3、4 习题
- [综合文档]浙江省深化普通高中课程改革
- [综合文档]CRISP原理 - 图文
- [综合文档]2017年电大社会调查研究与方法形考答案
- [综合文档]浅析建筑施工安全毕业论文
- [综合文档]《回忆我的母亲》名师教案
- [综合文档]装饰装修工程监理规划
- [综合文档]三下乡心得体会-文艺
- [综合文档]柱计算长度系数 - 图文
- [综合文档]全流程思考,提高燃电系统热电转换率--
- [综合文档]2018年嘉定区中考物理一模含答案
- 433M车库门滚动码遥控器
- 8、架空线路施工规范
- 大学四年声乐学习的体会
- 新北师大版五年级数学上册《轴对称再认
- 部编版五年级上册语文第六单元小结复习
- 小学六年级英语形容词用法
- 第2课 抗美援朝保家卫国 课件01(岳麓版
- 2015年天津大学运筹学基础考研真题,考
- 微机计算机控制技术课后于海生(第2版)
- 安全教育实践活动
- Delphi程序设计教程_第1章_Delphi概述
- 第八讲 工业革命与启蒙运动
- 《中华人民共和国药典》2005年版二部勘
- 科粤版九年级化学2.3构成物质的微粒(1)
- 西师大版数学三年级下册《长方形、正方
- ch6_冒泡排序演示
- 第4章 冲裁模具设计
- 浙江中小民营企业员工流失论文[终稿]
- 再议有线数字电视市场营运模式
- 昆明供水工程监理大纲




