Overclock.net - Overclocking.net
     
 
Home Gallery Reviews Blogs Register Today's Posts Mark Forums Read Members List


Go Back   Overclock.net - Overclocking.net > Software, Programming and Coding > Coding and Programming

Reply
 
LinkBack Thread Tools
Old 03-25-07   #1 (permalink)
Audiophile
 
welfinator's Avatar
 
intel nvidia

Join Date: Jan 2007
Location: New Jersey
Posts: 243

Rep: 14 welfinator Unknown
Unique Rep: 13
Trader Rating: 0
Default Need help with Java

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:
/**
* Write a description of class BinaryTree here.
*
* @author (your name)
* @version (a version number or a date)
*/
public abstract class BinaryTree
{
TreeNode root;

public BinaryTree()
{
root = null;
}

public TreeNode getRoot()
{
return root;
}

public void setRoot(TreeNode newNode)
{
root = newNode;
}

public boolean isEmpty()
{
return root == null;
}

public abstract void insert(Comparable item);
public abstract TreeNode find(Comparable key);
}
i have no idea how to do this program any help will be appreciated
__________________
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

System: Dell XPS M1530
CPU
Intel® Core™ 2 Duo Processor T8300 (2.4GHz/800Mhz
Memory
4GB Shared Dual Channel DDR2 SDRAM at 667MHz (2 Di
Graphics Card
256MB NVIDIA® GeForce® 8600M GT
Hard Drive
Size: 320GB 5400rpm SATA Hard Drive
Sound Card
High Definition Audio 2.0
Power Supply
85 WHr 9-cell Lithium Ion Primary Battery
Case
Tuxedo Black
OS
Windows Vista
Monitor
Full Hi Definition, glossy widescreen 15.4 inch LC
welfinator is offline   Reply With Quote
Old 03-25-07   #2 (permalink)
Photography nut
 
dangerousHobo's Avatar
 
amd nvidia

Join Date: Dec 2005
Location: ~/
Posts: 3,470

FAQs Submitted: 7
Folding Team Rank: 390
Trader Rating: 0
Default

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:
Originally Posted by Melcar
Only one reasonable way to solve this... a dance off.

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

System: Anomaly
CPU
Athlon 3700 SD(KACAE)0546 @3.02ghz
Motherboard
DFI UT nF4 Ultra-D
Memory
G.Skill 2x512 UTT(BH-5)
Graphics Card
evga 6800gs
Hard Drive
Maxtor 300GB + WD 250GB
Sound Card
onboard
Power Supply
Ultra 500w V-series
Case
one from Ultra
CPU cooling
Big Typhoon
GPU cooling
80mm fan mounted on
OS
Arch64
Monitor
Acer AL2216W 22" WS LCD
dangerousHobo is offline I fold for Overclock.net Overclocked Account dangerousHobo's Gallery   Reply With Quote
Old 03-25-07   #3 (permalink)
AMD Overclocker
 
decompiled's Avatar
 
amd nvidia

Join Date: Feb 2006
Location: Redsox Nation
Posts: 468

Rep: 47 decompiled is acknowledged by some
Unique Rep: 45
Hardware Reviews: 9
Trader Rating: 0
Default

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
You would evaluate this as ( 9 - 3 ) + ( 4 * 2 ) or 6 + 8 = 14

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 =).

System: Slow Poke
CPU
AMD X2 4400
Motherboard
MSI K8N Diamond +
Memory
3gb TCC5
Graphics Card
eVGA 7900GS
Hard Drive
74gb Raptor + Raid 1 640's
Sound Card
Audigy SE
Power Supply
OCZ 520 PowerStream
Case
Antec P180
CPU cooling
Stock AMD
GPU cooling
Stock eVGA
OS
Vista x64
Monitor
Dell 1905FP
decompiled is offline   Reply With Quote
Old 03-26-07   #4 (permalink)
Audiophile
 
welfinator's Avatar
 
intel nvidia

Join Date: Jan 2007
Location: New Jersey
Posts: 243

Rep: 14 welfinator Unknown
Unique Rep: 13
Trader Rating: 0
Default

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

System: Dell XPS M1530
CPU
Intel® Core™ 2 Duo Processor T8300 (2.4GHz/800Mhz
Memory
4GB Shared Dual Channel DDR2 SDRAM at 667MHz (2 Di
Graphics Card
256MB NVIDIA® GeForce® 8600M GT
Hard Drive
Size: 320GB 5400rpm SATA Hard Drive
Sound Card
High Definition Audio 2.0
Power Supply
85 WHr 9-cell Lithium Ion Primary Battery
Case
Tuxedo Black
OS
Windows Vista
Monitor
Full Hi Definition, glossy widescreen 15.4 inch LC
welfinator is offline   Reply With Quote
Old 03-26-07   #5 (permalink)
110100001101001111000
 
C-bro's Avatar
 
intel nvidia

Join Date: Jan 2006
Location: Hamilton, ON
Posts: 1,832

Rep: 283 C-bro is a proven memberC-bro is a proven memberC-bro is a proven member
Unique Rep: 215
FAQs Submitted: 6
Folding Team Rank: 237
Hardware Reviews: 9
Trader Rating: 1
Default

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.

System: RAID0R
CPU
Intel E2180 3.33GHz
Motherboard
Asus P5K-E/WIFI-AP vMod
Memory
2GB Kingmax DDR2-1066
Graphics Card
EVGA 8800GT
Hard Drive
2x250GB WD+500GB 7200.11
Sound Card
SB Audigy 2
Power Supply
Corsair CMPSU-550VX
CPU cooling
Arctic Cooling Freezer 7 Pro
GPU cooling
Zalman VF900-Cu
OS
Windows Vista Business 32-Bit
Monitor
HP F2105 21" & Samsung 712N
C-bro is offline I fold for Overclock.net Overclocked Account C-bro's Gallery   Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools



All times are GMT -4. The time now is 02:11 PM.


Overclock.net is a Carbon Neutral Site Creative Commons License Internet Security By ControlScan

Terms of Service / Forum Rules | Privacy Policy | Advertising | Become an Official Vendor
Copyright © 2008 Shogun Interactive Development. Most rights reserved.
Page generated in 0.65760 seconds with 8 queries