ComputerScienceExpert

(11)

$18/per page/

About ComputerScienceExpert

Levels Tought:
Elementary,Middle School,High School,College,University,PHD

Expertise:
Applied Sciences,Calculus See all
Applied Sciences,Calculus,Chemistry,Computer Science,Environmental science,Information Systems,Science Hide all
Teaching Since: Apr 2017
Last Sign in: 103 Weeks Ago, 3 Days Ago
Questions Answered: 4870
Tutorials Posted: 4863

Education

  • MBA IT, Mater in Science and Technology
    Devry
    Jul-1996 - Jul-2000

Experience

  • Professor
    Devry University
    Mar-2010 - Oct-2016

Category > Programming Posted 09 May 2017 My Price 9.00

Rust program

Rust program questions: Write a complete Rust program that follows the requirement below. Thank you.

Write a [postfix](https://en.wikipedia.org/wiki/Reverse_Polish_notation) expression evaluator. An expression consists of operands and operators. An operand is a signed integer (`isize`). An operator is `+`, `-`, or `*` with their common semantics. An expression is valid if it can be evaluated to a signed integer.

For example, the following are valid expressions:

```
-100
1 2 +
1 2 3 + *
```

The following expressions are invalid:

```
// empty expression
-1 -2
1 2 + *
```

## Public API

Your program must provide the following public API.

```
pub enum Operator {
    // `+`
    Add, 
    // `-`
    Sub,
    // `*`
    Mul,
}

pub enum Token {
    Operator(Operator),
    Operand(isize),
}

/// Evaluates the postix expression.
///
/// Input: a postfix expression, where each element contains an operator or operand.
/// Returns: if the postfix expression is valid, returns `Some(value)`;
///     otherwise, returns `None`.
pub fn eval(tokens: &[Token]) -> Option<isize> {
    // TODO
    unimplemented!();
}
```

Answers

(11)
Status NEW Posted 09 May 2017 09:05 AM My Price 9.00

-----------

Not Rated(0)