私は次のコードで3つの関数を実装することになっています。スタック付きJavaインフィックス/ポストフィックスコンバータ
Functions:
1. evaluate arithmetic expression in postfix
2. convert arithmetic expression from infix to postfix
3. convert arithmetic expression from postfix to infix
私はどこから始めればいいのか、どのように機能を見たり/作り上げる必要があるのか全く分かりません。あなたがこれらの3つの機能のうちの1つで私を助けることができれば、おそらく他の2つの機能を実行することができます。ここで
はコードです:ここでは
import java.util.Stack;
public class Postfix {
public static int evalPostfix(String postfix) {
// TODO
}
public static String infixToPostfix(String infix) {
// TODO
}
public static String postfixToInfix(String postfix) {
// TODO
}
public static void main(String[] args) {
String infix1 = "(3-(7*2))";
String postfix1 = "372*-";
int eval1 = -11;
String infix2 = "((7+1)*((3-6)*(5-2)))";
String postfix2 = "71+36-52-**";
int eval2 = -72;
System.out.println(" postfix1: " + postfix1);
int n = evalPostfix(postfix1);
System.out.println("evalPostfix(postfix1): " + n);
if (n == eval1) {
System.out.println(" Right!");
} else {
System.out.println(" Wrong!");
}
System.out.println();
System.out.println(" infix1: " + infix1);
String s = infixToPostfix(infix1);
System.out.println("infixToPostfix(infix1): " + s);
if (s.equals(postfix1)) {
System.out.println(" Right!");
} else {
System.out.println(" Wrong!");
}
System.out.println();
System.out.println(" postfix1: " + postfix1);
s = postfixToInfix(postfix1);
System.out.println("postfixToInfix(postfix1): " + s);
if (s.equals(infix1)) {
System.out.println(" Right!");
} else {
System.out.println(" Wrong!");
}
System.out.println();
System.out.println(" postfix2: " + postfix2);
n = evalPostfix(postfix2);
System.out.println("evalPostfix(postfix2): " + n);
if (n == eval2) {
System.out.println(" Right!");
} else {
System.out.println(" Wrong!");
}
System.out.println();
System.out.println(" infix2: " + infix2);
s = infixToPostfix(infix2);
System.out.println("infixToPostfix(infix2): " + s);
if (s.equals(postfix2)) {
System.out.println(" Right!");
} else {
System.out.println(" Wrong!");
}
System.out.println();
System.out.println(" postfix2: " + postfix2);
s = postfixToInfix(postfix2);
System.out.println("postfixToInfix(postfix2): " + s);
if (s.equals(infix2)) {
System.out.println(" Right!");
} else {
System.out.println(" Wrong!");
}
System.out.println();
}
}
掲載されていることすべてがプログラムであります説明Hあなたは[特定の質問をする]必要があります(http://stackoverflow.com/help/how-to-ask)。私たちが答えることができる有効な質問を含めるために投稿を編集してください。注意:あなたが知っていることを確認してください(ここにトピックは何ですか?)(http://stackoverflow.com/help/on-topic)、あなたとあなたのためにプログラムを書くように頼んでください。 –