home *** CD-ROM | disk | FTP | other *** search
/ MACD 7 / MACD7.iso / www / weirdscience / classes / tree.class (.txt) < prev    next >
Encoding:
Java Class File  |  1997-06-14  |  1.1 KB  |  58 lines

  1. public class Tree {
  2.    public TreeNode root = new TreeNode();
  3.    private static int item;
  4.    private static int count;
  5.    private static TreeNode foundNode;
  6.  
  7.    public Tree() {
  8.       this.root.data = new TreeNodeData();
  9.    }
  10.  
  11.    public TreeNode getRoot() {
  12.       return this.root;
  13.    }
  14.  
  15.    public boolean rootItem() {
  16.       return this.root.nextNode != null;
  17.    }
  18.  
  19.    public TreeNode findItem(int var1) {
  20.       item = var1;
  21.       count = -1;
  22.       this.findLoop(this.root);
  23.       return foundNode;
  24.    }
  25.  
  26.    private void findLoop(TreeNode var1) {
  27.       if (var1 != null) {
  28.          if (count++ == item) {
  29.             foundNode = var1;
  30.          } else {
  31.             this.findLoop(var1.subNode);
  32.             this.findLoop(var1.nextNode);
  33.          }
  34.       }
  35.    }
  36.  
  37.    public void updateNodes(TreeNode var1, TreeNode var2) {
  38.       if (var1 != null) {
  39.          for(TreeNode var3 = var1.lastNode; var3.data.level > 0; var3 = var3.lastNode) {
  40.             var3.data.mark = false;
  41.          }
  42.       }
  43.  
  44.       if (var2 != null) {
  45.          TreeNode var5 = var2.lastNode;
  46.  
  47.          for(TreeNode var4 = var2; var5.data.level > 0; var5 = var5.lastNode) {
  48.             if (var5.subNode == var4) {
  49.                var5.data.mark = true;
  50.             }
  51.  
  52.             var4 = var5;
  53.          }
  54.       }
  55.  
  56.    }
  57. }
  58.