|
![]() |
Overclock.net - Overclocking.net > Software, Programming and Coding > Coding and Programming | |
Need help with Java
|
||
![]() |
|
|
LinkBack | Thread Tools |
|
|
#1 (permalink) | |||||||||||
|
Audiophile
|
ok so my teacher gave us this project to program and i am lost:
our job is to: Implement an expression evaluator that uses a parser to build an expression tree. Then use postorder traversal to evaluate the expression, using a stack for the intermediate results. this is my binary tree class: Quote:
__________________
Think for yourself... http://www.last.fm/user/germanguru69/ ^stuff i listen to ![]() http://hs.facebook.com/profile.php?id=1342020499 ^add me on facebook
|
|||||||||||
|
|
|
|
|
#2 (permalink) | ||||||||||||||
|
Photography nut
![]() |
Well since your class BinaryTree is abstract your going to want to make a class that extends BinaryTree.
Could you give some more information on the project, as I'm a bit confused myself.
__________________
"UNIX was never designed to keep people from doing stupid things, because that policy would also keep them from doing clever things." - Doug Gwyn Try out the latest Programming Challenge Quote:
CPU-Z Validation @ 2.97-prime95 stable 16 hours @ 1.48v Proof | CPU-Z Validation @ 3.15 Getting Mouse Side Buttons to work in Linux, Compile a custom Kernel, More
|
||||||||||||||
|
|
|
|
#3 (permalink) | |||||||||||||
|
AMD Overclocker
|
Do you understand what post order traversal is?
To do a postorder traversal of a binary tree 1. Traverse the left subtree; and then 2. traverse the right subtree; and then 3. visit the root. So... you want to write code that goes as far left down the tree as possible then when it can't go to the root node then go right and try to go as far left as possible. A great example is: Code:
+
/ \
- *
/ \ / \
9 3 4 2
Starting left we get 9. Then we go up to root which is -. Then we traverse right. Because there is no left child to the node with 3 we evaluate the expression as 9 - 3. Then we move to Root which is + and descend down the right side of the tree to 4 and work our way back up. Hope this helps =).
|
|||||||||||||
|
|
|
|
|
#4 (permalink) | ||||||||||
|
Audiophile
|
thanks guys for the help, i think i got it now my teacher kinda hbelped me lol
__________________
Think for yourself... http://www.last.fm/user/germanguru69/ ^stuff i listen to ![]() http://hs.facebook.com/profile.php?id=1342020499 ^add me on facebook
|
||||||||||
|
|
|
|
|
#5 (permalink) | ||||||||||||
|
110100001101001111000
|
Are you allowed to use the Stack class that's built into Java?
If not, I have my own that I had to program for a project. I can pass it on if you'd like. I did it with generics, so it should work fine for your application.
__________________
|
||||||||||||
|
|
![]() |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
|
|