-6
這是我在壓縮後綴特里將節點插入代碼:未解決的編譯錯誤
public class tree {
char a[] = new char[10];
a[0]='b';
a[1]='a';
a[2]='n';
a[3]='a';
a[4]='n';
a[5]='a';
a[6]=' ';
protected node root;
public tree() {
this.root = new node();
}
public void inorder(node n) {
if (n.getChildren().next != null) {
inorder(n.getChildren().next.getChild());
}
System.out.println(n.getStart() + n.getEnd());
if (n.getChildren().next.next != null) {
inorder(n.getChildren().next.next.getChild());
}
}
public void insert(node n, node r) {
while (n.getStart() != 6) {
if (r.getChildren().next == null) {
//when the tree is empty :
n.setParent(r);
n.getChildren().setNext(null);
link newn = new link();
newn.setNext(null);
newn.setChild(n);
r.getChildren().next = newn;
node newnode = n;
newnode.setStart(n.getStart() + 1);
insert(newnode, r);
}
else {
// count is the node where we begin checking for same letters :
node count = r.getChildren().next.getChild();
// l is the linked list containing children of the node :
link l = r.getChildren().next;
while ((a[count.getStart()] != a[n.getStart()])
|| (l.next != null)) {
l = l.next;
count = l.getChild();
}
// create a new link node corresponding to the node to be inserted
// only for the case when we reach the end of the list :
link h = new link();
h.setNext(null);
h.setChild(n);
// we have reached the end of the linked list :
if ((a[count.getStart()] != a[n.getStart()])
&& (l.next == null)) {
if (n.getStart() != n.getEnd()) {
l.setNext(h);
h.setNext(null);
h.setChild(n);
n.setParent(r);
n.getChildren().setNext(null);
node newnode = n;
newnode.setStart(n.getStart() + 1);
insert(newnode, r);
}
else {
l.setNext(h);
h.setNext(null);
h.setChild(n);
n.setParent(r);
n.getChildren().setNext(null);
node newnode = new node();
newnode.setStart(count.getStart() + 1);
newnode.setEnd(n.getEnd());
}
}
// if we have found an element whose characters
// match that of the node:
else {
link kids = count.getChildren();
int x = count.getStart();
int y = n.getStart();
int p = count.getEnd();
int q = n.getEnd();
int t1 = count.getStart();
int t2 = n.getStart();
int length = p - x + 1;
int same = 1;
while (a[x + 1] == a[y + 1]) {
x++;
y++;
same++;
}
int g = length - same;
//modifying the node r:
count.setStart(t1);
count.setEnd(x);
// creating the 2 new nodes to be inserted below count if
// count initially doesnt have any children :
node kid1 = new node();
kid1.setStart(x + 1);
kid1.setEnd(p);
kid1.getChildren().setNext(null);
node kid2 = new node();
kid2.setStart(y + 1);
kid2.setEnd(q);
// creating 2 new link nodes to be inserted in
// the children list of count :
link k1 = new link();
link k2 = new link();
k1.setChild(kid1);
k2.setChild(kid2);
k1.setNext(k2);
k2.setNext(null);
//changing relationships :
kid1.setChildren(kids);
kid1.setParent(count);
count.getChildren().next.setNext(k1);
while (kids.next != null) {
kids.next.getChild().setParent(kid1);
kids = kids.next;
}
insert(kid2, count);
}
}
}
}
public static void main(String[] args) {
tree t = new tree();
node banana = new node();
banana.setStart(0);
banana.setEnd(7);
banana.getChildren().setNext(null);
t.insert(banana, t.root);
//inorder(tree.root);
}
}
當我在Eclipse中運行它,它說,它有一些尚未解決的問題彙編。 你能幫我解決這個問題嗎?謝謝。
什麼是錯誤??? – 2013-03-06 17:29:41
在哪一行中,您遇到了編譯問題,錯誤是什麼? – 2013-03-06 17:29:51
請用英文大寫字母:) – iberbeu 2013-03-06 17:31:06