중위표기식 후위표기식으로 변환
#include
#include
#include
using namespace std;
stack s;
char print[99999];
int i=0;
int precedence(int op){
if (op == '(') return 3;
if (op == '+' || op == '-') return 1;
if (op == '*' || op == '/') return 2;
else return 0;
}
int cal(char a){
if(a=='('){
s.push('(');
}
else if(a==')'){
while(s.top()!='('){
print[i]=s.top();
i++;
s.pop();
}
s.pop();
}
else if(a=='+'||a=='-'||a=='*'||a=='/'){
while(precedence(s.top())>=precedence(a)){
print[i]=s.top();
i++;
s.pop();
s.push(a);
}
}
else{
print[i]=a;
i++;
}
}
int main(void){
char a;
int j;
for(;a=')';){
a=getche();
cal(a);
}
while(!s.empty()){
print[i]=s.top();
s.pop();
}
for(i=j;j<=i;j++)
{
printf("%c",print[j]);
}
return(0);
}
이렇게 짜긴 했는데....
실행하면 글씨를 쓰다가 글씨가 써지지를 않습니다. 그 밖에도 오류가 많은 것 같은데 어떻게 고쳐야 할까요?
댓글 달기