For this assignment you will be building a program to evaluate fully parenthesized arithmetic expressions using Dijkstra's Two Stack Algorithm for expression evaluation.
Djikstra's two stack algorithm is a way to evaluate fully parenthesized infix expressions.
- Infixed expressions are those where the operators are placed between two operands, (2 + 4) is an infix expression.
- Full parenthesized means that every operator and it's operands are contained in parentheses, which means precedence and associativity do not matter.
An example expression:
For each element in the expression, the following rules are applied:
Element | Action |
---|---|
Operand | Push to stack 1 |
Operator | Push to stack 2 |
Left Parenthesis | Ignore |
Right Parenthesis | Pop an operator from stack 2 and two values from stack 1; apply the operator to the two operands; pushed the result to stack 1 |
Using only these simple rules, and two functioning stacks, you can solve any infix fully parenthesized expression!
This assignment will be hosted on Github Classroom.
- Register for the assignment on our Github Classroom using this link
- Be sure to select your name from the list to link your Github to the class roster!
- Clone the repository to your machine
- Open a terminal
- Navigate to your algorithms folder
- Go to the parent directory (
cd ..
) - Clone the repository to this location (
git clone <your repository link here>
)- Be sure to use the link for your copy of the repository for the assignment
- Getting things in order
- Open your new folder in VS Code
- In your folder you should have:
calculator.cpp
,source/Algorithms/twostack.hpp
,source/Linear/Stack.test.cpp
andsource/Linear/Stack.cpp
. - Check that you can compile and run your calculator program
make calculator
- Check that you can compile and run the Two Stack starter code
make twostack
- Ensure that your test cases fail.
- Implement the
main
function (30 points)- Following the pseudocode in
calculator.cpp
, implement the main function for your calculator.
- Following the pseudocode in
- Implement the algorithm (60 points)
- Write pseudocode for your algorithm
- Commit and push this pseudocode (
git add . && git commit -m "<message>" && git push
)- Check that your pseudocode uploaded, and is visible on the master branch of your assignment.
- Implement the Stack datatype, as it is not provided.
- Implement your pseudocode in C++
- Pass all unit tests
- Commit and push your code (
git add . && git commit -m "<message>" && git push
)- Check that all of your working code is uploaded, and visible on the master branch of your assignment.
- Analyze your work (10 points)
- Provide your algorithms' Big-Oh notation as a function of expression length.
Criteria | Points |
---|---|
Functionality | 70 |
Analysis | 10 |
Quality | 20 |
To submit this assignment, simply commit and push your work to your assignment repository. Your last submission before the deadline will be graded.