English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

Pseudocode in JAVA will be fine... for a method that performs a range query for a binary search tree.

That is, the method should visit all items that have a search key within a given range of values. For example, all values between 100 and 1000.

2007-12-07 18:54:49 · 1 answers · asked by javaHungerForce 3 in Computers & Internet Programming & Design

1 answers

void search (Collection result, Constraints c, Node n ) {

if (n.left()!=null) {
search (result,c,n.left());
}

if (n.right()!=null) {
search (result,c,n.right());
}

if (this.isOk(c)) {
result.add(this);
}

}

this algorith visits recursively all nodes, it doesnt assume any ordering on the nodes except that it is a binary tree.

isOk(c) should return true if the node satisfies the constraints you want for the nodes.

results are collected in results.

2007-12-07 19:25:15 · answer #1 · answered by gjmb1960 7 · 1 0

fedest.com, questions and answers