Giter VIP home page Giter VIP logo

rpn-calcualtor-lab's Introduction

Reverse Polish Notation Calculator Lab

We've probably all seen infix notation for arithmetic expressions, i.e. (1+2)*3=9. However there exists another way of writing these expressions in what is called postfix notation or reverse polish notation. For example, the follwing infix

(1+2)*3

becomes the following in reverse polish notation

1 2 + 3 *

where the binary operation follows the pair of values it should be applied to. Using this new notation we have to evaluate expressions correctly. This might be made easier with use of a new data structure, stack.

Objective

  • Implement a stack with the use of a linked list data structure
  • Utilize stacks to manage values and applying binary operations
  • Implement a fully functional postfix calculator

Setup A Stack

Using the linked list you've implemented today, create a Stack data structure that allows you to just push and pop items in and out of a collection respectively. Do not use a ruby array to implement the stack! Also, make sure you get the specs to pass for the stack before moving on to the calculator.

Operations to Manage

Your calculator should handle all arthemetic operations, i.e. +, -, *, /, and ^. Here would be a good point to utilize case statements

Reading Input

Data should be expected in lines of complete expressions that should be read from left to right. Input being read should be on the stack until an operation is read and two values are popped off to be evaluated. After reading terminates, only one value should be left on the stack, which should be popped off and returned as the result.

Rafi has also generously provided us with some postfix expressions to use for the purposes of testing our calculators abilities, here

BONUS

Write the calculator program such that if a command line argument for the file name is passed, then the file name is parse and evaluated. Otherwise, make the program take a string from the user that is immediately parsed and displayed.

rpn-calcualtor-lab's People

Contributors

mayormcmatt avatar tigarcia avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.