-
Notifications
You must be signed in to change notification settings - Fork 277
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
第六章 第四节逆波兰计算器示例代码错误 #49
Comments
请用一个 pull request 或补丁来说明, 方便看出差异.
2025-01-03 13:04:32"gaomei052" ***@***.***>写道:
原代码
{ for(i=1;i<=NF;i++){ if($i ~ /^[+-]?([0-9]+[.]?[0-9]*|[.][0-9]+$)/){ stack[++top] = $i continue }else if($i == "+" && top > 1){ stack[top-1] += stack[top];top-- }else if($i == "-" && top >1){ stack[top-1] -= stack[top] top-- }else if($i == "*" && top > 1){ stack[top-1] *= stack[top];top-- }else if($i == "/" && top > 1){ stack[top-1] /= stack[top];top-- }else if($i == "^" && top > 1){ stack[top-1] ^= stack[top];top-- }else{ printf("error: cannot evaluate %s\n",$i) top = 0 next } if(top == 1){ printf("\t%.8g\n",stack[top--]) }else if(top > 1){ printf("error: too many operands\n") top = 0 } } }
更改后的代码
{ top = 0 for(i=1;i<=NF;i++){ if($i ~ /^[+-]?([0-9]+[.]?[0-9]*|[.][0-9]+$)/){ stack[++top] = $i continue }else if($i == "+" && top > 1){ stack[top-1] += stack[top];top-- }else if($i == "-" && top >1){ stack[top-1] -= stack[top] top-- }else if($i == "*" && top > 1){ stack[top-1] *= stack[top];top-- }else if($i == "/" && top > 1){ stack[top-1] /= stack[top];top-- }else if($i == "^" && top > 1){ stack[top-1] ^= stack[top];top-- }else{ printf("error: cannot evaluate %s\n",$i) top = 0 next } if(top == 1 && i == NF){ printf("\t%.8g\n",stack[top]) }else if(top > 1 && i == NF){ printf("error: too many operands\n") top = 0 } } }
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.Message ID: ***@***.***>
|
已提交pr |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
原代码
{ for(i=1;i<=NF;i++){ if($i ~ /^[+-]?([0-9]+[.]?[0-9]*|[.][0-9]+$)/){ stack[++top] = $i continue }else if($i == "+" && top > 1){ stack[top-1] += stack[top];top-- }else if($i == "-" && top >1){ stack[top-1] -= stack[top] top-- }else if($i == "*" && top > 1){ stack[top-1] *= stack[top];top-- }else if($i == "/" && top > 1){ stack[top-1] /= stack[top];top-- }else if($i == "^" && top > 1){ stack[top-1] ^= stack[top];top-- }else{ printf("error: cannot evaluate %s\n",$i) top = 0 next } if(top == 1){ printf("\t%.8g\n",stack[top--]) }else if(top > 1){ printf("error: too many operands\n") top = 0 } } }
更改后的代码
{ top = 0 for(i=1;i<=NF;i++){ if($i ~ /^[+-]?([0-9]+[.]?[0-9]*|[.][0-9]+$)/){ stack[++top] = $i continue }else if($i == "+" && top > 1){ stack[top-1] += stack[top];top-- }else if($i == "-" && top >1){ stack[top-1] -= stack[top] top-- }else if($i == "*" && top > 1){ stack[top-1] *= stack[top];top-- }else if($i == "/" && top > 1){ stack[top-1] /= stack[top];top-- }else if($i == "^" && top > 1){ stack[top-1] ^= stack[top];top-- }else{ printf("error: cannot evaluate %s\n",$i) top = 0 next } if(top == 1 && i == NF){ printf("\t%.8g\n",stack[top]) }else if(top > 1 && i == NF){ printf("error: too many operands\n") top = 0 } } }
The text was updated successfully, but these errors were encountered: