Giter VIP home page Giter VIP logo

cpp-coding-challenge's Introduction

Cpp-Coding-Challenge

The challenge is about implmenting a c++ program to parse an arithmetic expression like 3+(5+(4*3))-12 and print it's value (for the example the result should be 8). In this problem i used the Reverse Polish Notation algorithm https://en.wikipedia.org/wiki/Reverse_Polish_notation. The idea is about to create a queue and stack that stores the operators, then exploit the queue to calcuate the result.

How to get the queue ?

First we will use a queue and a stack were we keep track the operators used in the expression. When parsing the expression if we find a number push it to the queue. otherwise if it's an operator, if the stack is empty just push it to the stack, else we pop operators from the stack and push them to queue as long as the curent operator we found in the expression has priority greater than or the curent operator from the stack. Example if this is the stack : + - * and the curent operator is / then we find that the prioriy of / and * are equal so we push * in the queue, and the stack became + -. Now the priority of / is greater than the priority of + and - so pop them from the stack and push them to the queue, and the stack now is empty so there is no more comparaisons we push / in the stack. Now the stack is just contain the / operator.The queue now is * - + .

cpp-coding-challenge's People

Contributors

ayoubc avatar

Watchers

 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.