Advertisement
Guest User

Untitled

a guest
Oct 31st, 2014
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.91 KB | None | 0 0
  1. import java.util.ArrayList;
  2.  
  3. public class Node{  
  4.    
  5.     public ArrayList<Node> childNode;
  6.     private int estimatedScore;
  7.    
  8.     public Node(){
  9.         childNode = new ArrayList<Node>();
  10.     }
  11.    
  12.     public int getScore()
  13.     {
  14.         return estimatedScore;
  15.     }
  16.  
  17.     public void setScore(int estimatedScore)
  18.     {
  19.         this.estimatedScore = estimatedScore;
  20.     }
  21.    
  22.     public void addChildNode(Node n){
  23.         childNode.add(n);
  24.     }
  25.    
  26.     public String toString(){
  27.         return "-- Node:"+ estimatedScore+"--";
  28.     }
  29.    
  30.     public void buildTree(int depth){
  31.         System.out.println("(" + estimatedScore + ")");
  32.         for(int j=0; j<childNode.size(); j++){
  33.             if(this.values()){
  34.                 for(int k=0; k<depth; k++){
  35.                     System.out.println("\t");
  36.                 }
  37.                 childNode.get(j).buildTree(depth+1);
  38.             }
  39.             else System.out.println("(" + estimatedScore +")");
  40.         }
  41.     }
  42.    
  43.     public boolean values(){
  44.         if(childNode.size()>0) return true;
  45.         else return false;
  46.     }
  47.    
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement