以下是使用java的二进制搜索树的简单实现.但是,代码总是输出"BST空!!" 尽管插入元素.我哪里错了?我怀疑我的递归出错了.任何帮助是极大的赞赏.
public class BinarySearchTree {
NODE root;
BinarySearchTree(){
root = null;
}
void insert(NODE nodeptr,int key){
if(root == null){
nodeptr = new NODE(key);
return;
}
if(nodeptr == null){
nodeptr = new NODE(key);
return;
}
if(key <= nodeptr.data){
insert(nodeptr.left,key);
}
else{
insert(nodeptr.right,key);
}
}
void inorder(NODE nodeptr){
if(nodeptr == null){
System.out.println("BST empty!!");
return;
}
inorder(nodeptr.left);
System.out.println(nodeptr.data + " ");
inorder(nodeptr.right);
}
/*driver program*/
public static void main(String args[]){
int[] a = {20,30,40,24,39};
BinarySearchTree bst = new BinarySearchTree();
for (int i: …Run Code Online (Sandbox Code Playgroud) 我有以下模式和字符串的注册匹配问题.模式基本上是一个名称,后跟任意数量的字符,后跟一个短语(见下面的模式),后跟任意数量的字符,后跟机构名称.
pattern = "[David Maxwell|David|Maxwell] .* [educated at|graduated from|attended|studied at|graduate of] .* Eton College"
str = "David Maxwell was educated at Eton College, where he was a King's Scholar and Captain of Boats, and at Cambridge University where he rowed in the winning Cambridge boat in the 1971 and 1972 Boat Races."
match = re.search(pattern, str)
Run Code Online (Sandbox Code Playgroud)
但搜索方法返回上述str的不匹配?我的注册表适合吗?我是reg-ex的新手.任何帮助表示赞赏