@@ -32,7 +32,7 @@ def infix_2_postfix(infix: str) -> str:
32
32
print (
33
33
"Symbol" .center (8 ),
34
34
"Stack" .center (print_width ),
35
- "Postfix" .rjust ((print_width - 7 ) // 2 + 7 ),
35
+ "Postfix" .rjust ((print_width - 7 ) // 2 + 7 ),
36
36
sep = " | " ,
37
37
)
38
38
print ("-" * (print_width * 3 + 7 ))
@@ -60,20 +60,20 @@ def infix_2_postfix(infix: str) -> str:
60
60
):
61
61
post_fix .append (stack .pop ()) # pop stack & add to Postfix
62
62
stack .append (x ) # push x to stack
63
-
63
+
64
64
if post_fix != []:
65
65
print (
66
66
x .center (8 ),
67
67
("" .join (stack )).ljust (print_width ),
68
68
"" .join (post_fix ),
69
69
sep = " | " ,
70
- ) # Output in tabular format
70
+ ) # Output in tabular format
71
71
72
- else : # Post_fix is empty -> remove trailing space in table
72
+ else : # Post_fix is empty -> remove trailing space in table
73
73
print (
74
74
x .center (8 ) + " | " + ("" .join (stack )).ljust (print_width ) + " |"
75
- ) # Output in tabular format
76
-
75
+ ) # Output in tabular format
76
+
77
77
while len (stack ) > 0 : # while stack is not empty
78
78
if stack [- 1 ] == "(" : # open bracket with no close bracket
79
79
raise ValueError ("Invalid bracket position(s)" )
@@ -85,7 +85,6 @@ def infix_2_postfix(infix: str) -> str:
85
85
"" .join (post_fix ),
86
86
sep = " | " ,
87
87
) # Output in tabular format
88
-
89
88
90
89
return "" .join (post_fix ) # return Postfix as str
91
90
0 commit comments