错误:解析时到达文件末尾

时间:2016-10-18 19:17:28

标签: java compiler-errors

所以我有一个红黑树的java代码。

public class RedBlackBST<Key extends Comparable<Key>, Value> 

    {
        private Node root;
        private class Node // BST node with color bit (see page 433)
        private boolean isRed(Node h); // See page 433.
        private Node rotateLeft(Node h); // See page 434.
        private Node rotateRight(Node h); // See page 434.
        private void flipColors(Node h); // See page 436.
        private int size(); // See page 398.

        public void put(Key key, Value val){ // Search for key. Update value if found; grow table if new.
            root = put(root, key, val);
            root.color = BLACK;
        }

        private Node put(Node h, Key key, Value val) {
           //inserts the value into the tree
        }
    }

这是我的节点类:

private static final boolean RED = true;
private static final boolean BLACK = false;
private class Node {
    Key key; // key
    Value val; // associated data
    Node left, right; // subtrees
    int N; // # nodes in this subtree
    boolean color; // color of link from
    // parent to this node
    Node(Key key, Value val, int N, boolean color) {
        this.key = key;
        this.val = val;
        this.N = N;
        this.color = color;
    }
}

奇怪的是,每次运行它时,我都会在RedBlackBST代码的最后一行收到错误消息error: reached end of file while parsing。问题是我检查了并且我的括号已关闭所以它不应该给我这个错误,但它是如此我只是想知道它为什么这么说。

1 个答案:

答案 0 :(得分:1)

Node类的语法错误。 private static final boolean值应该在类中,然后必须可以从其他类访问它们:

private class Node {

  public static final boolean RED = true;
  public static final boolean BLACK = false;

  Key key; // key
  Value val; // associated data
  Node left, right; // subtrees
  int N; // # nodes in this subtree
  boolean color; // color of link from
  // parent to this node
  Node(Key key, Value val, int N, boolean color) {
    this.key = key;
    this.val = val;
    this.N = N;
    this.color = color;
  }
}