Hey all, I have some code here for a red black tree that prints out in preorder traversal. The entire program works fine and prints out to a file when I run from the terminal "java Main.java<input1.txt>output.txt", however I need set it up so it writes to standard output "output.txt" in the program. The problem I am having is when I write it out, it is getting caught in recursion and is only printing the last line, any suggestions?

public static void preorderwalk(Tree t,Node n){
    if(n!=t.nil){
     System.out.print(n.color);
     System.out.println(" " +n.value);
     preorderwalk(t, n.left);
     preorderwalk(t, n.right);
    }
}

Not enough info to determine what the problem is. Please post your entire program.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.