강의

멘토링

커뮤니티

Inflearn Community Q&A

jinho20700406's profile image
jinho20700406

asked

Introduction to Python Algorithm Problem Solving (Coding Test Preparation)

3. Creating a postfix notation: infix-->postfix (stack)

while문 이상해서 질문드립니다!!

Written on

·

236

0

안녕하세요.

"섹션5. - 3번_후위표기식 만들기" 질문이 있습니다.

for x in data:

    if x.isdecimal():

        res += x

    else:

        if x == '(':

            stack.append(x)

        elif x == '*' or x == '/':

            while stack and (stack[-1] == '*' or stack[-1] == '/'):

                res =+ stack.pop()

            stack.append(x)

...

... 

...

연산자가 곱셈(*)이랑 나눗셈(/)일때,  while문에서는

아래의 다른 while문들과는 다르게, '(' 연산자가 나오면 멈춰야하는  != '('  가 있는데 왜, 위에 쓴 while문에는 없는지 모르겠습니다.

똑같이  != '('  를 입력해줬는데 돌아가긴 하더라구요. 혹시 넣어도 되는 부분인지, 아니면 넣어주면 안되는지 궁금합니다 ㅠㅠㅠ

코테 준비 같이 해요! python

Answer 1

0

*,  / 는 연산자 우선순위가 높으므로 ( 이 있는것과 마찬가지입니다.

jinho20700406's profile image
jinho20700406

asked

Ask a question