Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tree practice #6

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open

Tree practice #6

wants to merge 6 commits into from

Conversation

dri19tcc
Copy link

Pseudocode:

  1. Because an expression trees leaves are all the values or numbers that will be added, it goes to show that if a node has descendants, it would be an operator and not a number. So to get this, an if statement in the print out that only prints out if a node has descendants, otherwise, it won't print out.
  2. As above, we would have to check if the node has descendants so an if statement that has a node with descendants would contain an operator. If you go inside that if statement, then you would add to a counter to check how many operators it has.
  3. To print out prefix notation, when you first go to the right, have an if statement that prints out the operators, the else would then print out the leaf nodes. Postfix would be the opposite.
  4. The method would receive a string as an argument that would be the operator of choice. As you go down the tree nodes on both the left and the right, you would check to see if the given operator existed, if it does, return the number of times it occurred and return the counter if it returns 0, then there would have been none of that operator, else it would return the counter with as many times at it occurred.
    TDD:
  5. To test this case, I would write a few test cases that have different operators and test to make sure that it returned the operators that it was suppose to.
  6. I would do like the above, but since this returns a counter I would check to see if the number of operators included would be the same number of operators as expected
  7. I would write a test that had a binary tree and check to see if the operators were printed in the correct order.
  8. I would test this case by checking to see the correct number was returned. I would test to see that it returns 0 when the operator did not occur in the expression, else return the number of times it did occur.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant