Binary search tree not working, when it should. Any idea what am i doing wrong. any help would be much appreciated.
this is the error:
Exception in thread "main" java.lang.Error: Unresolved compilation problems:
The method iprint(Node1) in the type BST is not applicable for the arguments ()
The method preprint(Node1) in the type BST is not applicable for the arguments ()
at MainBST.main(MainBST.java:38)
code for my main:
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;
public class MainBST {
public static void main(String[] args) throws FileNotFoundException
{
BST mytree = new BST();
String file2 = "infile2.txt";
String file3 = "inFile3.txt";
addData(file2, "[,\n\r]+", mytree);
addData(file3, "[\t\n\r]+", mytree);
System.out.println("-------------Pre-order------------------");
mytree.iprint();
System.out.println("---------------In-Order-----------------");
mytree.preprint();
}
private static void addData(String filepath, String delimiter, BST tree) throws FileNotFoundException
{
File file = new File(filepath);
Scanner sc = new Scanner(file).useDelimiter(delimiter);
while(sc.hasNext())
{
tree.add(sc.next(), sc.next(), sc.nextInt());
}
}
}
code for my BST
public class BST {
Node1 root;
public BST() {
root = null;
}
public void add(String fname, String lname, int age) {
Node1 NewNode = new Node1(lname, fname, age);
Node1 compare = root;
if (root == null)
root = NewNode;
else {
while (true) {
if (NewNode.age < compare.age) {
if (compare.lChild == null) {
compare.lChild = NewNode;
break;
}
compare = compare.lChild;
} else {
if (compare.rChild == null) {
compare.rChild = NewNode;
break;
}
compare = compare.rChild;
}
}
}
}
public void iprint(Node1 t) {
if (t != null) {
iprint(t.lChild); // left
System.out.println(t); // data
iprint(t.rChild); // right
}
}
public void preprint(Node1 t) {
if (t != null) {
System.out.println(t); // data
preprint(t.lChild); // left
preprint(t.rChild); // right
}
}
}
code for my Node1
public class Node1 {
String lname;
String fname;
int age;
Node1 lChild;
Node1 rChild;
public Node1( String l, String f, int a)
{
this.lname = l;
this.fname = f;
this.age = a;
lChild = null;
rChild = null;
}
public String toString()
{
return(" the age for "+fname+" "+ lname +" is "+ age);
}
}