收藏 分享(赏)

中缀表达式转换为后缀表达式C语言程序.doc

上传人:hwpkd79526 文档编号:7719795 上传时间:2019-05-24 格式:DOC 页数:4 大小:24KB
下载 相关 举报
中缀表达式转换为后缀表达式C语言程序.doc_第1页
第1页 / 共4页
中缀表达式转换为后缀表达式C语言程序.doc_第2页
第2页 / 共4页
中缀表达式转换为后缀表达式C语言程序.doc_第3页
第3页 / 共4页
中缀表达式转换为后缀表达式C语言程序.doc_第4页
第4页 / 共4页
亲,该文档总共4页,全部预览完了,如果喜欢就下载吧!
资源描述

1、/1.h#ifndef STACK_H#define STACK_H#include#includetypedef struct astack *Stack;typedef struct astackint top;int maxtop;char* data;Astack;Stack NewEmpty(int size)Stack S=(Stack)malloc(sizeof(Astack);S-maxtop=size;S-top=-1;S-data=(char*)malloc(size*sizeof(char);return S;int StackEmpty(Stack S)return S

2、-toptop=S-maxtop;int Peek(Stack S)return S-dataS-top;void Push(char x,Stack S)if(StackFull(S)printf(“Stack is full!n“);exit(1);elseS-data+S-top=x;int Pop(Stack S)if(StackEmpty(S)printf(“Stack is empty!n“);exit(1);else return S-dataS-top-;Stack NewStack(int size)Stack S=NewEmpty(size);int i,x,num;pri

3、ntf(“Please enter the number of data:n“);scanf(“%d“,for(i=0;itop;i+)printf(“ %c“,S-datai);printf(“n“);#endif/1.c#include#include#include#include“1.h“#define MAX 30int Precedence(char ch)if(ch=+|ch=-)return 2;else if(ch=*|ch=/)return 3;else if(ch=(|ch=)return 4;else if(ch=)return 1;else return 0;void

4、 Change(char *s1,char *s2)Stack S=NewEmpty(MAX);int i=0,j=0,one=0;char ch=s1i;Push(,S);while(ch!=)if(ch= )ch=s1+i;else if(isalnum(ch)!=0)if(one=1)s2j+= ;s2j+=ch;ch=s1+i;one=0;else if(ch=()Push(ch,S);ch=s1+i;one=1;else if(ch=)while(Peek(S)!=()s2j+=Pop(S);Pop(S);ch=s1+i;one=1;else if(ch=+|ch=-|ch=*|ch=/)while(Peek(S)!=(one=1;Push(ch,S);ch=s1+i;one=1;while(StackEmpty(S)!=1)s2j+=Pop(S);one=1;s2j=0;int main()char s1MAX,s2MAX;printf(“Enter the equation:n“);gets(s1);Change(s1,s2);printf(“%sn“,s2);return 0;

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

当前位置:首页 > 企业管理 > 管理学资料

本站链接:文库   一言   我酷   合作


客服QQ:2549714901微博号:道客多多官方知乎号:道客多多

经营许可证编号: 粤ICP备2021046453号世界地图

道客多多©版权所有2020-2025营业执照举报