그래서 저는 현재 숙제를 위해 Postfix와 Infix 표현식에 Stack을 사용하고 있습니다. 내 질문은, 어떻게 내가 밀어 넣을 수 있도록 스택을 설정 및 문자 및 두 번 팝업. 지금은 Postfix에서 중위가 올바르게 작동하도록 중급을 얻을 수 있지만 후미에 대한 총을 계산하려고하면 폭탄이됩니다. 지금은 문자 A-Z의 값을 저장할 배열을 사용하고 있습니다. 이것은 내 postFix 평가 함수입니다.숯과 이중 스택
public double postFix(String infix, double[] numbers) throws Exception{
Stack myStack=new Stack();
for(int i=0; i<infix.length(); i++){
char ch=infix.charAt(i);
if(ch=='+'){
char one=(char) myStack.pop();
char two=(char) myStack.pop();
double first=numbers[one-65], second=numbers[two-65];
double temp=first+second;
myStack.push((char) temp);
}
else if(ch=='-'){
char one=(char) myStack.pop();
char two=(char) myStack.pop();
double first=numbers[one-65], second=numbers[two-65];
double temp=first-second;
myStack.push((char) temp);
}
else if(ch=='*'){
char one=(char) myStack.pop();
char two=(char) myStack.pop();
double first=numbers[one-65], second=numbers[two-65];
double temp=first*second;
myStack.push((char) temp);
}
else if(ch=='/'){
char one=(char) myStack.pop();
char two=(char) myStack.pop();
double first=numbers[one-65], second=numbers[two-65];
double temp=first/second;
myStack.push((char) temp);
}
else if(ch=='^'){
char one=(char) myStack.pop();
char two=(char) myStack.pop();
double first=numbers[one-65], second=numbers[two-65];
double temp=Math.pow(first, second);
myStack.push((char) temp);
}
else{
myStack.push(ch);
}
}
return myStack.pop();
이것은 내 노드 클래스
private class Node{
protected char data;
protected Node next;
private Node(){
this.data=(Character) null;
this.next=null;
}
private Node(char data, Node next){
this.data=data;
this.next=next;
}
}
당신이 저에서 필요한 아무것도 물어 주시기 바랍니다가있는 경우
나는이 두 가지 스택을 만들어야합니까? 여기