小编rag*_*ghu的帖子

Java通过递归传递值

以下是使用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)

java oop recursion parameter-passing binary-search-tree

3
推荐指数
1
解决办法
427
查看次数

python reg-ex模式不匹配

我有以下模式和字符串的注册匹配问题.模式基本上是一个名称,后跟任意数量的字符,后跟一个短语(见下面的模式),后跟任意数量的字符,后跟机构名称.

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的新手.任何帮助表示赞赏

python regex

0
推荐指数
1
解决办法
53
查看次数