data_structures.stacks.infix_to_prefix_conversion¶
Output:
- Enter an Infix Equation = a + b ^c
Symbol | Stack | Postfix
b | ^ | cb + | + | cb^ a | + | cb^a
| cb^a+a+b^c (Infix) -> +a^bc (Prefix)
Attributes¶
Functions¶
|
|
|
Module Contents¶
- data_structures.stacks.infix_to_prefix_conversion.infix_2_postfix(infix: str) str ¶
>>> infix_2_postfix("a+b^c") Symbol | Stack | Postfix ---------------------------- a | | a + | + | a b | + | ab ^ | +^ | ab c | +^ | abc | + | abc^ | | abc^+ 'abc^+'
>>> infix_2_postfix("1*((-a)*2+b)") Symbol | Stack | Postfix ------------------------------------------- 1 | | 1 * | * | 1 ( | *( | 1 ( | *(( | 1 - | *((- | 1 a | *((- | 1a ) | *( | 1a- * | *(* | 1a- 2 | *(* | 1a-2 + | *(+ | 1a-2* b | *(+ | 1a-2*b ) | * | 1a-2*b+ | | 1a-2*b+* '1a-2*b+*'
>>> infix_2_postfix("") Symbol | Stack | Postfix ---------------------------- ''
>>> infix_2_postfix("(()") Traceback (most recent call last): ... ValueError: invalid expression
>>> infix_2_postfix("())") Traceback (most recent call last): ... IndexError: list index out of range
- data_structures.stacks.infix_to_prefix_conversion.infix_2_prefix(infix: str) str ¶
>>> infix_2_prefix("a+b^c") Symbol | Stack | Postfix ---------------------------- c | | c ^ | ^ | c b | ^ | cb + | + | cb^ a | + | cb^a | | cb^a+ '+a^bc'
>>> infix_2_prefix("1*((-a)*2+b)") Symbol | Stack | Postfix ------------------------------------------- ( | ( | b | ( | b + | (+ | b 2 | (+ | b2 * | (+* | b2 ( | (+*( | b2 a | (+*( | b2a - | (+*(- | b2a ) | (+* | b2a- ) | | b2a-*+ * | * | b2a-*+ 1 | * | b2a-*+1 | | b2a-*+1* '*1+*-a2b'
>>> infix_2_prefix('') Symbol | Stack | Postfix ---------------------------- ''
>>> infix_2_prefix('(()') Traceback (most recent call last): ... IndexError: list index out of range
>>> infix_2_prefix('())') Traceback (most recent call last): ... ValueError: invalid expression
- data_structures.stacks.infix_to_prefix_conversion.Infix¶