Homework Assignment 2
- (10 points) Implement a stack in Racket.
- (10 points) Write a Racket function called postfix (or something similar) that
takes a single argument that is a list containing a postfix expression
and returns the result of evaluating that expression.
Allow the operators +, *, -, and /.
(postfix '(1 2 + 3 4 + *)) produces 21.
- (15 points) Write a Racket function called prefix (or something similar) that
takes a single argument that is a list containing a postfix expression
and returns a Racket list that has the same operations and produces the same value.
Allow the operators +, *, -, and /.
(postfix '(1 2 + 3 4 + *)) produces '(* (+ 1 2 ) (+ 3 4)).
- (15 points) Write a Racket function called infix (or something similar) that
takes a single argument that is a list containing an infix expression
and returns a list that has an infix representation of the expression
Allow the operators +, *, -, and /.
(postfix '(1 2 + 3 4 + *)) produces '((1 + 2) * (3 + 4)).
Copyright © 2019, David A. Reimann. All rights reserved. |
|