• Post Reply Bookmark Topic Watch Topic
  • New Topic

Binary Tree Constructor  RSS feed

 
Michael Boyd
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am writing a binary tree constructor that uses three variables as inputs: BinaryTree left, Object e, and BinaryTree right; BinaryTree left and right are previoiusly defined trees, or they can be null initially, and e is the new root. The constructor constructs a tree from the bottom up.
Basically, my problem is the syntax needed for this, I have tried coding it but it never quite works and is quite frankly driving me up the wall. Anyone know how to set this up?
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Welcome to JavaRanch!

Is that it?
 
Michael Boyd
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That sounds about right, although the code that I have to test the constructor indicates that the root should be a node of some sort; in that case, do I just create a node and make it a root? Thanks a lot for the help.
Also one more thing, would I need to import anything, such as java.util, java.awt, etc?
[ December 05, 2003: Message edited by: Michael Boyd ]
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

the code that I have to test the constructor indicates that the root should be a node of some sort; in that case, do I just create a node and make it a root?

Well, this is your design, not mine; but I took it that the Object was the data at the root, not the root node itself. The root node would be the BinaryTree object that held that data, right -- so constructing another BinaryTree object around it doesn't sound right. Note that I'm using BinaryTree itself as a "node" in the Binary Tree; you could break these two roles apart if you wished and have a separate Node class.
Given the code that I wrote, you don't need to import anything, no, because I didn't use any API classes.
 
Thomas Paul
mister krabs
Ranch Hand
Posts: 13974
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Beginner? I don't think so. Moving this to intermediate.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!