Question: Please write this code IN RUST LANGUAGE. Don't copy from somewhere else, thank you! # Homework 2: From Infix to Postfix Expressions Submiesion instructions cargo
Please write this code IN RUST LANGUAGE. Don't copy from somewhere else, thank you!


# Homework 2: From Infix to Postfix Expressions Submiesion instructions cargo new 2 name your ed 2 Save your program in src/lib.rs git add Cargo.toml erc/lib.re git commit git remote add origin metastasis@gradebot.org:user/username)1/2 git pueh origin master Because postfix expreesione are simpler and faster to evaluate, compilere transform infix expressions in source programe to postfix expressions in executable programs. You will implement this transformation ** Infix expressions An infix expression contains one or more of the following tokens: * operands; integers, such as 1,-23. * Operators: arithmetic operators-+ , , and with their normal association and Left and right parentheses A valid infix expression must satisfy all the following rules: *An operand or left parentheaia cannot be preceded by an operand or right parentheeis An operator or right parenthesis annot *be the firat token in the expression, or be preceded by an operator or left parentheais *An operator or left parentheie cannot be the last token in the expreasion Each left parenthesis must match a unique right parenthesis, and vice versa Tranaform infix to postfix e expresa1on 1. Create a etack 2. Scan the tokens in the infix expression If the token is an operand, output it If the token is a left parenthesie, push it onto the etac!k If the token ia a right parentheais, pop and output all the operators from the stack until encountering a left parenthesis. Pop and diacard the left parenthesis If the token is an operator If the tack is empty, push the token onto the tack otherwise, if the top of the stack is an operator and its precedence ia greater than or egual to the precedence of the token, pop and output the operator from the atack, and repeat this process. Finall y, push the token in the in Eix expression onto the stack
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
