Java Visitor Pattern

  • + 2 comments

    Hi, your solution is very neat. I like it. And do you have any second thought on handing one node tree. You didn't actually put anything into values[] and colors[] yet.

    /* Handle 1-node tree */
            if (numNodes == 1) {
                return new TreeLeaf(values[0], colors[0], 0);
            }
    

    Maybe you mean

    if (numNodes ==1) {
        		int single_value = scan.nextInt();
        		int single_color = scan.nextInt();
        		TreeLeaf leaf = new TreeLeaf(single_value, Color.values()[single_color],0);    		
        		return leaf;
        	}