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;