私はこの情報を与えられた学校のプロジェクトを手に入れました:
for i=1 to m
if c_i is an operand: Transfer c_i to output.
if c_i is a left parentheses: Push c_i to tmp.
if c_i is a right parentheses: Pop elements from tmp and transfer
them to output until a left-parentheses
is met. Pop left-parentheses.
if c_i is an operator: Let the top tmp element be t. Pop and
transfer elements from tmp to output
until:
p(t) < p(c_i) or
t is a left-parentheses or
tmp is empty.
Push c_i to tmp.
Transfer the remaining elements in tmp to output.
私はこれらの手順を正確に実行してきましたが、私の出力は数回しか正しくなりません。演算子を使用したifステートメントのどこかで間違っていると思います。私は2日間常にデバッグを続けてきましたが、解決策が見つかりません。
誰かが私のコードをチェックしてくれたら、とてもうれしいです。operatorCheck 関数は、これを解決するために作成されました。「サブルーチン p を使用して、演算子の優先度を指定します。
p(+) = 0,
p(−) = 0, p(∗) = 1, p(/) = 1
. これは、足し算と引き算は、掛け算と割り算よりも優先度が低いことを意味します。」
コード: http://pastebin.com/TA7UGiGc
ありがとうございました!