-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPostFix.java
More file actions
34 lines (28 loc) · 856 Bytes
/
Copy pathPostFix.java
File metadata and controls
34 lines (28 loc) · 856 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
package stack;
import java.util.*;
public class PostFix {
public int evaluatePostFix(String exp){
Stack<String> stack = new Stack<String>();
List<String> storage = new ArrayList<String>();
for(int i=0;i<exp.length();i++){
String val = exp.substring(i,i+1);
if((val=="*")||(val=="+")||(val=="/")||(val=="-")){
int symbol = Integer.parseInt(val);
int val1,val2;
if(!storage.isEmpty()){
val1=Integer.parseInt(storage.get(0));
}
val1=Integer.parseInt(stack.pop());
val2=Integer.parseInt(stack.pop());
int calc;
}
else{
stack.push(val);
}
}
}
public static void main(String[] args) {
PostFix pf = new PostFix();
pf.evaluatePostFix("123+*8-");
}
}