C++
- voluntas
- @ignis_fatuus
- ブン
- @Linda_pp
- 清楚なC++メイドBOT
- @tzik_tack
- 長谷川一輝
- wraith13
- @jj1bdx
- @cpp_akira
- 安藤敏彦
- @srz_zumix
- Siv3D
- takezoh
- まろ
- @okdshin
- @hnokx
- @ishidakei
- @take_cheeze
- TAKEI Yuya
- @mumumu
- I (@wx257osn2)
- Tommy6
- @tyottyoworks
- ___shanon
- わたやん
- @KorekaraSEDB
- @kariya_mitsuru
- @ciniml
- @beam2d
- @grafi_tt
- @nekketsuuu
- LouiS0616
- @volanja
- 大鎌広
- むてら
- ガチKGB
- 三重野賢人
x
246
else if( precedence(infix[i]) <= precedence(operators.arr[operators.top])) {1
2
using namespace std;3
class Stack{4
public:5
char arr[10];6
int top=-1;7
int push(char);8
char pop();9
};10
class Evaluate_infix{11
char infix[20];12
char postfix[20];13
Stack operators;14
Stack operand;15
public:16
void printPostfix();17
void readInfix();18
void Infix_Postfix();19
void postfix_eval();20
int precedence (char);21
};22
void Evaluate_infix::readInfix()23
{24
25
cout<<"\nEnter the infix expression : "; 26
cin>>infix;27
28
}29
void Evaluate_infix::Infix_Postfix()30
{31
int i=0,k=0;32
while(infix[i]!='\0')33
{34
if((int)infix[i]>=49 && (int)infix[i]<=57) 35
{36
postfix[k]=infix[i];37
i++;38
k++;39
} 40
else if(infix[i]=='(' || infix[i]=='{' || infix[i]=='[')41
{42
operators.push(infix[i]);43
i++;44
} 45
else if(infix[i]==')' || infix[i]=='}' || infix[i]==']')46
{47
if(infix[i]==')')48
{49
while(operators.arr[operators.top]!='(')50
{ 51
postfix[k]=operators.pop();52
k++;53
}54
operators.pop();55
i++;56
57
}58
if(infix[i]==']')59
{60
while(operators.arr[operators.top]!='[')61
{62
postfix[k]=operators.pop();63
k++;64
}65
operators.pop();66
i++;67
}68
69
if(infix[i]=='}')70
{71
while(operators.arr[operators.top]!='{')72
{73
postfix[k]=operators.pop();74
k++;75
}76
operators.pop();77
i++;78
}79
}80
else $ g++ prog.cc -Wall -Wextra -std=c++11 -pedantic
Stdin
2+3Start
Enter the infix expression : The converted postfix string is : 23+ Postfix Evaluation : 5
0
Finish