Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

DesertFox

macrumors member
Original poster
Nov 25, 2004
72
0
Hello,

Im trying to declare a tree in java, but it keeps giving me an error when I try to delcare it. Is my syntax for declaring the tree correct?

The error occurs on line 6 (Tree theTree = new Tree) and the error message is:
Error: '(' or '[' expected

class TreeApp
{
public static void main(String[] args)
{
// make a tree
Tree theTree = new Tree;
int min;


// create a 15 node tree by inserting 15 items
theTree.insert(50, 1.5);
theTree.insert(25, 1.7);
theTree.insert(45, 4.9);
theTree.insert(78, 6.9);
theTree.insert(90, 7.9);
theTree.insert(74, 9.9);
theTree.insert(87, 3.9);
theTree.insert(26, 1.4);
theTree.insert(75, 1.6);
theTree.insert(89, 4.5);
theTree.insert(90, 5.6);
theTree.insert(90, 5.2);
theTree.insert(72, 6.3);
theTree.insert(63, 9.3);
theTree.insert(81, 7.9);


// find node with minimum key value
min = theTree.minimum();

// display tree using inorder traversal
theTree.inOrder(min);

// delete three internal nodes
theTree.delete(75);
theTree.delete(63);
theTree.delete(74);

// display tree using inorder traversal
theTree.inOrder(min);


// TESTING FINDS //
node found = theTree.find(25); // find node with key 25
if(found != null)
System.out.println("Found the node with key 25");
else
System.out.println("Could not find node with key 25");
} // end main()

} // end class TreeApp

Thanks in advance!
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.