home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftp.ee.pdx.edu
/
2014.02.ftp.ee.pdx.edu.tar
/
ftp.ee.pdx.edu
/
pub
/
users
/
harry
/
cse509
/
hw6.txt
< prev
next >
Wrap
Text File
|
2002-03-09
|
2KB
|
62 lines
CSE 509 -- HW #6
==================
Date Due: Wed, 13 March 2002
Goals:
- Gain a minimal familiarity with Java
Requirements:
Create a small Java program to manipulate a Binary Tree data structure. This
program should have two classes. One class, called "Node," will represent the
nodes in the binary tree. Each instance will contain a "label", as well as
references to left and right children. The other class, called "Tree," will
have a "main" method and a static field pointing to the root Node. There will
be no instances of the "Tree" class.
The Node labels will be Strings and the binary tree will be kept "in order,"
sorted by the labels on the nodes.
The "Node" and "Tree" classes may have several methods, as you see fit, but
the "Tree" class will need at least these two (static) methods:
Tree . add (String label)
Tree . print ()
The "print()" method will walk the tree (doing an "in-order" traversal) and
print each node. It can print each node label on a separate line.
The "add()" method will add a new Node to the tree. It will insert it at the
appropriate place in the tree, preserving the order of the tree. The "add()"
method will presumably deal with the case of an empty tree and then call a
recursive method of the Node class.
The main method should be a sequence of calls to "add" and "print," such as:
public static void main (String [] args) {
Tree.add ("Vijay");
Tree.add ("Brenda");
Tree.add ("Yao");
Tree.add ("Darrel");
Tree.add ("Jolly");
Tree.add ("Kim");
Tree.add ("Doug");
Tree.add ("Ofir");
Tree.add ("Lisa");
Tree.add ("Steven");
Tree.add ("Bingbing");
Tree.add ("Fan");
Tree.print ();
}
Please place both classes in a single file; no need to mess with packages and
this makes it simpler for the grader.
What to hand in:
- E-mail a copy of your code to the harry@cs.pdx.edu.
- Please hand in a hard-copy of your code.