-
Notifications
You must be signed in to change notification settings - Fork 3
kth/계산기 1차 코드 리뷰 #2
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
base: kth/main
Are you sure you want to change the base?
Changes from 1 commit
3ff5220
3d40f99
a2d84a9
adee2c4
3dace13
0d743bd
f1db66f
d6b26c0
250674d
4dfb3b9
7ab770b
fd48306
a79039f
164cf9a
b528194
5d05bb9
ad1ca5d
5b6986c
00a52a0
ecd0d2d
7beba5c
7551509
3557acc
f0b3c9f
527efac
06ab0ee
d14b8bd
8066eb2
1ea1141
90746b5
01f2074
28c4398
da609f1
93f245e
2905ce4
c9bcc79
f755333
4e2831c
eedc44c
57f95cf
476aed8
8048649
bddb95f
fb2677d
cf0898b
e3049bb
7cc00b6
0b70d47
f7565d3
a26b217
58a2f06
0e4b06c
71928f3
0b728d3
2410415
2256b3e
a157b8b
74c7172
53e1a08
b7cb3ab
5dc13a4
503e594
1c27980
05b3b99
35c6e77
5d9a319
5f2e78e
a1fa676
87dcb6b
7107d5c
123488d
2c23bcb
5ae1ab2
5dd678d
308f1c7
cfddb59
a5bfd08
8152b7f
f399249
79a839f
1cc812a
7d1273a
18d1e37
0d0ade7
dc51378
8eadf1b
6a09420
d06b78e
0a02174
6ce8564
e8baa79
d2292a4
f0e3eda
fd87dbc
48b595b
c106797
6be3443
b2d4465
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,35 +3,55 @@ | |
| import java.util.Arrays; | ||
| import java.util.Stack; | ||
| import operator.Operator; | ||
| import util.PatternValidator; | ||
|
|
||
| public class InfixToPostfixConverter { | ||
|
|
||
| private String postfix = ""; | ||
| private StringBuilder postfix = new StringBuilder(); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 변수명이 무엇을 저장하는건지 와닿지 않아요. |
||
|
|
||
|
|
||
| public String changeToPostFix(String expression) { | ||
| Stack<String> operatorStack = new Stack(); | ||
| String[] splitExpression = expression.split(" "); | ||
| Arrays.stream(splitExpression).forEach(str -> { | ||
| Operator operator = Operator.stringToOperator(str); | ||
| int operatorPriority = operatorPriority(operator); | ||
| int value = Integer.parseInt(str); | ||
| if (operatorPriority == -1) { | ||
| postfix += value + " "; | ||
| } else if (operatorStack.isEmpty()) { | ||
| operatorStack.add((value + " ")); | ||
| } else { | ||
| while (!operatorStack.isEmpty() | ||
| && operatorPriority(Operator.stringToOperator(operatorStack.peek().substring(0, 1))) | ||
| >= operatorPriority) { | ||
| postfix += operatorStack.pop(); | ||
| } | ||
| operatorStack.add((value + " ")); | ||
| } | ||
| Arrays.stream(splitExpression).forEach(token -> { | ||
| processToken(operatorStack, token); | ||
| }); | ||
| while (!operatorStack.isEmpty()) { | ||
| postfix += operatorStack.pop(); | ||
| postfix.append(operatorStack.pop()); | ||
| } | ||
| return postfix.toString(); | ||
| } | ||
|
|
||
| private void processToken(Stack<String> operatorStack, String token) { | ||
| if (PatternValidator.checkOperatorValue(token)) { | ||
| handleOperator(operatorStack, token); | ||
| } else if (!PatternValidator.checkOperatorValue(token)) { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ㅎㅎ.. 이 코드가 if else 랑 뭐가 다른가요 |
||
| handelOperand(token); | ||
| } | ||
| } | ||
|
|
||
| private void handelOperand(String token) { | ||
| int value = Integer.parseInt(token); | ||
| postfix.append(value).append(" "); | ||
| } | ||
|
|
||
| private void handleOperator(Stack<String> operatorStack, String token) { | ||
| Operator currentOperator = Operator.stringToOperator(token); | ||
| int currentOperatorPriority = operatorPriority(currentOperator); | ||
| setOperatorToOperatorStack(operatorStack, token,currentOperatorPriority); | ||
| } | ||
|
|
||
| private void setOperatorToOperatorStack(Stack<String> operatorStack, String token,int currentOperatorPriority) { | ||
| compareOperatorPriority(operatorStack,currentOperatorPriority); | ||
| operatorStack.add((token + " ")); | ||
| } | ||
|
|
||
| private void compareOperatorPriority(Stack<String> operatorStack,int currentOperatorPriority) { | ||
| Operator topStackOperator = Operator.stringToOperator(operatorStack.peek().substring(0, 1)); | ||
| int topStackOperatorPriority = operatorPriority(topStackOperator); | ||
| while (!operatorStack.isEmpty() && topStackOperatorPriority >= currentOperatorPriority) { | ||
| postfix.append(operatorStack.pop()); | ||
| } | ||
| return postfix; | ||
| } | ||
|
Comment on lines
+12
to
59
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 읽기 좋은 메서드란 메서드내에 코드가 5줄이면 가장 읽기 좋고 10줄 이내여야 합니다. |
||
|
|
||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
읽어보시면 중복되는 로직이고 이전에 연산자에 대한 연산 로직도 구현을 해두셨던 것 같은데 괴리감이 느껴지지않나요?