LintCode 367: Expression Tree Build (min-Tree和逆波兰表达式的应用,难题!)

本文介绍了解决构建表达式树问题的两种方法。一种是通过转换为逆波兰表达式,然后递归查找根节点;另一种是生成最小树,使用单调递减栈实现。详细解释了每种方法的代码实现。
  1. Expression Tree Build

The structure of Expression Tree is a binary tree to evaluate certain expressions.
All leaves of the Expression Tree have an number string value. All non-leaves of the Expression Tree have an operator string value.

Now, given an expression array, build the expression tree of this expression, return the root of this expression tree.

Example
Example 1:

Input: [“2”,"",“6”,"-","(",“23”,"+",“7”,")","/","(",“1”,"+",“2”,")"]
Output: {[-],[
],[/],[2],[6],[+],[+],#,#,#,#,[23],[7],[1],[2]}
Explanation:
The expression tree will be like

                 [ - ]
             /          \
        [ * ]              [ / ]
      /     \           /         \
    [ 2 ]  [ 6 ]      [ + ]        [ + ]
                     /    \       /      \
                   [ 23 ][ 7 ] [ 1 ]   [ 2 ] .

After building the tree, you just need to return root node [-].
Example 2:

Input: [“10”,"+","(",“3”,"-",“5”,")","+",“7”,"",“7”,"-",“2”]
Output: {[-],[+],[2],[+],[
],#,#,[10],[-],[7],[7],#,#,[3],[5]}
Explanation:
The expression tree will be like
[ - ]
/
[ + ] [ 2 ]
/ \
[ + ] [ * ]
/ \ /
[ 10 ] [ - ] [ 7 ] [ 7 ]
/ \
[3] [5]
After building the tree, you just need to return root node [-].
Clarification
See wiki:
Expression Tree

这题很难,下面两种解法都是参考自网上。
解法1:转换成逆波兰表达式,然后再递归找出root。
代码如下:

/**
 * Definition of ExpressionTreeNode:
 * class ExpressionTreeNode {
 * public:
 *     string symbol;
 *     ExpressionTreeNode *left, *right;
 *     ExpressionTreeNode(string symbol) {
 *         this->symbol = symbol;
 *         this->left = this->right = NULL;
 *     }
 * }
 */


class Solution {
public:
    /**
     * @param expression: A string array
     * @return: The root of expression tree
     */
    int getLevel(string opt) {
        if (opt == "(")
            return 0;
        if (opt == "+" || opt == "-")
            return 1;
        if (opt == "*" || opt == "/")
            return 2;

        return 3;
    }

    bool isOperator(string c) {
        return (c == "+" || c == "-" || c == "*" || c == "/");
    }
    //create reverse polish notation string
    vector<string> convertToRPN(vector<string> &expression) {
        stack<string> st;
        vector<string> RPN;
        int len = expression.size();
        for (int i = 0; i < len; ++i) {
            string c = expression[i];
            if (c == "(")
                st.push(c);
            else if (c == ")") {
                while (st.top() != "(") {
                    RPN.push_back(st.top());
                    st.pop();
                }
                st.pop();
            } else {
                if (!isOperator(c))
                    st.push(c);
                else {
                    while (!st.empty() && getLevel(st.top()) >= getLevel(c)) {
                            RPN.push_back(st.top());
                            st.pop();
                    }
                    st.push(c);
                }
            }
        }

        while (! st.empty()) {
            RPN.push_back(st.top());
            st.pop();
        }

        return RPN;
    }
    
    ExpressionTreeNode* build(vector<string> &expression) {
        vector<string> RPN = convertToRPN(expression);
        int len = RPN.size();
        stack<ExpressionTreeNode *> nodeStack;
        for (int i = 0; i < len; ++i) {
            string s = RPN[i];
            ExpressionTreeNode *pNode = new ExpressionTreeNode(s);
                if (s == "+" || s == "-" || s == "*" || s == "/") {
                    ExpressionTreeNode *pRight = nodeStack.top();
                    nodeStack.pop();
                    ExpressionTreeNode *pLeft = nodeStack.top();
                    nodeStack.pop();

                    pNode->right = pRight;
                    pNode->left = pLeft;
                    nodeStack.push(pNode);
            } else
                nodeStack.push(pNode);
        }       
        if (nodeStack.empty())
            return NULL;
        else
            return nodeStack.top(); 
    }
};

解法2:生成min-tree,然后用单调递减栈(栈底到栈底单调递减)。
代码如下:

/**
 * Definition of ExpressionTreeNode:
 * class ExpressionTreeNode {
 * public:
 *     string symbol;
 *     ExpressionTreeNode *left, *right;
 *     ExpressionTreeNode(string symbol) {
 *         this->symbol = symbol;
 *         this->left = this->right = NULL;
 *     }
 * }
 */
class MyTreeNode {
public:
    int val;
    ExpressionTreeNode * eNode;
    MyTreeNode(int v = 0, string s = ""){
        val = v;
        eNode = new ExpressionTreeNode(s);
    }
};

class Solution {
public:
    /**
     * @param expression: A string array
     * @return: The root of expression tree
     */
    ExpressionTreeNode* build(vector<string> & expression) {
        if (expression.size() == 0) {
            return NULL;
        }
        
        stack<MyTreeNode *> stk;
        int base = 0;
        int val = 0;

        for (int i = 0; i < expression.size(); i++) {
            if (expression[i] == "(") {
                base += 10;
                continue;
            }
            
            if (expression[i] == ")") {
                base -= 10;
                continue;
            }
            
            val = getWeight(base, expression[i]);
            
            MyTreeNode * node = new MyTreeNode(val, expression[i]);
            
            while (!stk.empty() && node->val <= stk.top()->val) {
                node->eNode->left = stk.top()->eNode;
                stk.pop();
            }
            
            if (!stk.empty()) {
                stk.top()->eNode->right = node->eNode;
            }
            
            stk.push(node);
        }
        
        if (stk.empty()) {
            return NULL;
        }
        
        MyTreeNode * rst = stk.top();
        stk.pop();
        
        while (!stk.empty()) {
            rst = stk.top();
            stk.pop();
        }
        return rst->eNode;
    }

private:
     //Calculate weight for characters
     int getWeight(int base, string s) {
        if (s == "+" || s == "-") {
            return base + 1;
        }
        
        if (s == "*" || s == "/") {
            return base + 2;
        }
        return INT_MAX;
    }
};
D:\develop\JDK\jdk1.8.0_271\bin\java.exe -XX:TieredStopAtLevel=1 -noverify -Dspring.output.ansi.enabled=always -Dcom.sun.management.jmxremote -Dspring.jmx.enabled=true -Dspring.liveBeansView.mbeanDomain -Dspring.application.admin.enabled=true "-javaagent:D:\soft\IDEA\IntelliJ IDEA 2022.1.2\lib\idea_rt.jar=62316:D:\soft\IDEA\IntelliJ IDEA 2022.1.2\bin" -Dfile.encoding=UTF-8 -classpath D:\develop\JDK\jdk1.8.0_271\jre\lib\charsets.jar;D:\develop\JDK\jdk1.8.0_271\jre\lib\deploy.jar;D:\develop\JDK\jdk1.8.0_271\jre\lib\ext\access-bridge-64.jar;D:\develop\JDK\jdk1.8.0_271\jre\lib\ext\cldrdata.jar;D:\develop\JDK\jdk1.8.0_271\jre\lib\ext\dnsns.jar;D:\develop\JDK\jdk1.8.0_271\jre\lib\ext\jaccess.jar;D:\develop\JDK\jdk1.8.0_271\jre\lib\ext\jfxrt.jar;D:\develop\JDK\jdk1.8.0_271\jre\lib\ext\localedata.jar;D:\develop\JDK\jdk1.8.0_271\jre\lib\ext\nashorn.jar;D:\develop\JDK\jdk1.8.0_271\jre\lib\ext\sunec.jar;D:\develop\JDK\jdk1.8.0_271\jre\lib\ext\sunjce_provider.jar;D:\develop\JDK\jdk1.8.0_271\jre\lib\ext\sunmscapi.jar;D:\develop\JDK\jdk1.8.0_271\jre\lib\ext\sunpkcs11.jar;D:\develop\JDK\jdk1.8.0_271\jre\lib\ext\zipfs.jar;D:\develop\JDK\jdk1.8.0_271\jre\lib\javaws.jar;D:\develop\JDK\jdk1.8.0_271\jre\lib\jce.jar;D:\develop\JDK\jdk1.8.0_271\jre\lib\jfr.jar;D:\develop\JDK\jdk1.8.0_271\jre\lib\jfxswt.jar;D:\develop\JDK\jdk1.8.0_271\jre\lib\jsse.jar;D:\develop\JDK\jdk1.8.0_271\jre\lib\management-agent.jar;D:\develop\JDK\jdk1.8.0_271\jre\lib\plugin.jar;D:\develop\JDK\jdk1.8.0_271\jre\lib\resources.jar;D:\develop\JDK\jdk1.8.0_271\jre\lib\rt.jar;D:\code\SpringCloud-hsp\code\e-commerce-center\e_commerce_eureka-server-9001\target\classes;D:\maven-repository\org\springframework\cloud\spring-cloud-netflix-eureka-server\2.2.1.RELEASE\spring-cloud-netflix-eureka-server-2.2.1.RELEASE.jar;D:\maven-repository\org\springframework\boot\spring-boot-starter-freemarker\2.2.2.RELEASE\spring-boot-starter-freemarker-2.2.2.RELEASE.jar;D:\maven-repository\org\freemarker\freemarker\2.3.29\freemarker-2.3.29.jar;D:\maven-repository\org\springframework\spring-context-support\5.2.2.RELEASE\spring-context-support-5.2.2.RELEASE.jar;D:\maven-repository\org\springframework\cloud\spring-cloud-commons\2.2.1.RELEASE\spring-cloud-commons-2.2.1.RELEASE.jar;D:\maven-repository\org\springframework\security\spring-security-crypto\5.2.1.RELEASE\spring-security-crypto-5.2.1.RELEASE.jar;D:\maven-repository\org\springframework\cloud\spring-cloud-netflix-hystrix\2.2.1.RELEASE\spring-cloud-netflix-hystrix-2.2.1.RELEASE.jar;D:\maven-repository\org\springframework\boot\spring-boot-autoconfigure\2.2.2.RELEASE\spring-boot-autoconfigure-2.2.2.RELEASE.jar;D:\maven-repository\org\springframework\boot\spring-boot-starter-aop\2.2.2.RELEASE\spring-boot-starter-aop-2.2.2.RELEASE.jar;D:\maven-repository\org\aspectj\aspectjweaver\1.9.5\aspectjweaver-1.9.5.jar;D:\maven-repository\org\springframework\cloud\spring-cloud-netflix-eureka-client\2.2.1.RELEASE\spring-cloud-netflix-eureka-client-2.2.1.RELEASE.jar;D:\maven-repository\com\netflix\eureka\eureka-client\1.9.13\eureka-client-1.9.13.jar;D:\maven-repository\org\codehaus\jettison\jettison\1.3.7\jettison-1.3.7.jar;D:\maven-repository\stax\stax-api\1.0.1\stax-api-1.0.1.jar;D:\maven-repository\com\netflix\netflix-commons\netflix-eventbus\0.3.0\netflix-eventbus-0.3.0.jar;D:\maven-repository\com\netflix\netflix-commons\netflix-infix\0.3.0\netflix-infix-0.3.0.jar;D:\maven-repository\commons-jxpath\commons-jxpath\1.3\commons-jxpath-1.3.jar;D:\maven-repository\joda-time\joda-time\2.10.5\joda-time-2.10.5.jar;D:\maven-repository\org\antlr\antlr-runtime\3.4\antlr-runtime-3.4.jar;D:\maven-repository\org\antlr\stringtemplate\3.2.1\stringtemplate-3.2.1.jar;D:\maven-repository\antlr\antlr\2.7.7\antlr-2.7.7.jar;D:\maven-repository\com\google\code\gson\gson\2.8.6\gson-2.8.6.jar;D:\maven-repository\org\apache\commons\commons-math\2.2\commons-math-2.2.jar;D:\maven-repository\javax\ws\rs\jsr311-api\1.1.1\jsr311-api-1.1.1.jar;D:\maven-repository\com\netflix\servo\servo-core\0.12.21\servo-core-0.12.21.jar;D:\maven-repository\com\sun\jersey\jersey-core\1.19.1\jersey-core-1.19.1.jar;D:\maven-repository\com\sun\jersey\contribs\jersey-apache-client4\1.19.1\jersey-apache-client4-1.19.1.jar;D:\maven-repository\org\apache\httpcomponents\httpclient\4.5.10\httpclient-4.5.10.jar;D:\maven-repository\org\apache\httpcomponents\httpcore\4.4.12\httpcore-4.4.12.jar;D:\maven-repository\commons-codec\commons-codec\1.13\commons-codec-1.13.jar;D:\maven-repository\com\google\inject\guice\4.1.0\guice-4.1.0.jar;D:\maven-repository\aopalliance\aopalliance\1.0\aopalliance-1.0.jar;D:\maven-repository\com\fasterxml\jackson\core\jackson-annotations\2.10.1\jackson-annotations-2.10.1.jar;D:\maven-repository\com\fasterxml\jackson\core\jackson-core\2.10.1\jackson-core-2.10.1.jar;D:\maven-repository\com\fasterxml\jackson\core\jackson-databind\2.10.1\jackson-databind-2.10.1.jar;D:\maven-repository\com\sun\jersey\jersey-servlet\1.19.1\jersey-servlet-1.19.1.jar;D:\maven-repository\com\sun\jersey\jersey-server\1.19.1\jersey-server-1.19.1.jar;D:\maven-repository\com\sun\jersey\jersey-client\1.19.1\jersey-client-1.19.1.jar;D:\maven-repository\com\netflix\eureka\eureka-core\1.9.13\eureka-core-1.9.13.jar;D:\maven-repository\com\fasterxml\woodstox\woodstox-core\5.2.1\woodstox-core-5.2.1.jar;D:\maven-repository\com\netflix\archaius\archaius-core\0.7.6\archaius-core-0.7.6.jar;D:\maven-repository\com\google\code\findbugs\jsr305\3.0.1\jsr305-3.0.1.jar;D:\maven-repository\commons-configuration\commons-configuration\1.8\commons-configuration-1.8.jar;D:\maven-repository\commons-lang\commons-lang\2.6\commons-lang-2.6.jar;D:\maven-repository\org\slf4j\slf4j-api\1.7.29\slf4j-api-1.7.29.jar;D:\maven-repository\com\google\guava\guava\16.0\guava-16.0.jar;D:\maven-repository\javax\inject\javax.inject\1\javax.inject-1.jar;D:\maven-repository\com\fasterxml\jackson\dataformat\jackson-dataformat-xml\2.10.1\jackson-dataformat-xml-2.10.1.jar;D:\maven-repository\com\fasterxml\jackson\module\jackson-module-jaxb-annotations\2.10.1\jackson-module-jaxb-annotations-2.10.1.jar;D:\maven-repository\org\codehaus\woodstox\stax2-api\4.2\stax2-api-4.2.jar;D:\maven-repository\com\thoughtworks\xstream\xstream\1.4.11.1\xstream-1.4.11.1.jar;D:\maven-repository\xmlpull\xmlpull\1.1.3.1\xmlpull-1.1.3.1.jar;D:\maven-repository\xpp3\xpp3_min\1.1.4c\xpp3_min-1.1.4c.jar;D:\maven-repository\org\springframework\boot\spring-boot-starter-web\2.2.2.RELEASE\spring-boot-starter-web-2.2.2.RELEASE.jar;D:\maven-repository\org\springframework\boot\spring-boot-starter\2.2.2.RELEASE\spring-boot-starter-2.2.2.RELEASE.jar;D:\maven-repository\org\springframework\boot\spring-boot\2.2.2.RELEASE\spring-boot-2.2.2.RELEASE.jar;D:\maven-repository\org\springframework\boot\spring-boot-starter-logging\2.2.2.RELEASE\spring-boot-starter-logging-2.2.2.RELEASE.jar;D:\maven-repository\ch\qos\logback\logback-classic\1.2.3\logback-classic-1.2.3.jar;D:\maven-repository\ch\qos\logback\logback-core\1.2.3\logback-core-1.2.3.jar;D:\maven-repository\org\apache\logging\log4j\log4j-to-slf4j\2.12.1\log4j-to-slf4j-2.12.1.jar;D:\maven-repository\org\apache\logging\log4j\log4j-api\2.12.1\log4j-api-2.12.1.jar;D:\maven-repository\org\slf4j\jul-to-slf4j\1.7.29\jul-to-slf4j-1.7.29.jar;D:\maven-repository\jakarta\annotation\jakarta.annotation-api\1.3.5\jakarta.annotation-api-1.3.5.jar;D:\maven-repository\org\yaml\snakeyaml\1.25\snakeyaml-1.25.jar;D:\maven-repository\org\springframework\boot\spring-boot-starter-json\2.2.2.RELEASE\spring-boot-starter-json-2.2.2.RELEASE.jar;D:\maven-repository\com\fasterxml\jackson\datatype\jackson-datatype-jdk8\2.10.1\jackson-datatype-jdk8-2.10.1.jar;D:\maven-repository\com\fasterxml\jackson\datatype\jackson-datatype-jsr310\2.10.1\jackson-datatype-jsr310-2.10.1.jar;D:\maven-repository\com\fasterxml\jackson\module\jackson-module-parameter-names\2.10.1\jackson-module-parameter-names-2.10.1.jar;D:\maven-repository\org\springframework\boot\spring-boot-starter-tomcat\2.2.2.RELEASE\spring-boot-starter-tomcat-2.2.2.RELEASE.jar;D:\maven-repository\org\apache\tomcat\embed\tomcat-embed-core\9.0.29\tomcat-embed-core-9.0.29.jar;D:\maven-repository\org\apache\tomcat\embed\tomcat-embed-el\9.0.29\tomcat-embed-el-9.0.29.jar;D:\maven-repository\org\apache\tomcat\embed\tomcat-embed-websocket\9.0.29\tomcat-embed-websocket-9.0.29.jar;D:\maven-repository\org\springframework\boot\spring-boot-starter-validation\2.2.2.RELEASE\spring-boot-starter-validation-2.2.2.RELEASE.jar;D:\maven-repository\jakarta\validation\jakarta.validation-api\2.0.1\jakarta.validation-api-2.0.1.jar;D:\maven-repository\org\hibernate\validator\hibernate-validator\6.0.18.Final\hibernate-validator-6.0.18.Final.jar;D:\maven-repository\org\jboss\logging\jboss-logging\3.4.1.Final\jboss-logging-3.4.1.Final.jar;D:\maven-repository\com\fasterxml\classmate\1.5.1\classmate-1.5.1.jar;D:\maven-repository\org\springframework\spring-web\5.2.2.RELEASE\spring-web-5.2.2.RELEASE.jar;D:\maven-repository\org\springframework\spring-beans\5.2.2.RELEASE\spring-beans-5.2.2.RELEASE.jar;D:\maven-repository\org\springframework\spring-webmvc\5.2.2.RELEASE\spring-webmvc-5.2.2.RELEASE.jar;D:\maven-repository\org\springframework\spring-aop\5.2.2.RELEASE\spring-aop-5.2.2.RELEASE.jar;D:\maven-repository\org\springframework\spring-context\5.2.2.RELEASE\spring-context-5.2.2.RELEASE.jar;D:\maven-repository\org\springframework\spring-expression\5.2.2.RELEASE\spring-expression-5.2.2.RELEASE.jar;D:\maven-repository\org\springframework\boot\spring-boot-starter-actuator\2.2.2.RELEASE\spring-boot-starter-actuator-2.2.2.RELEASE.jar;D:\maven-repository\org\springframework\boot\spring-boot-actuator-autoconfigure\2.2.2.RELEASE\spring-boot-actuator-autoconfigure-2.2.2.RELEASE.jar;D:\maven-repository\org\springframework\boot\spring-boot-actuator\2.2.2.RELEASE\spring-boot-actuator-2.2.2.RELEASE.jar;D:\maven-repository\io\micrometer\micrometer-core\1.3.1\micrometer-core-1.3.1.jar;D:\maven-repository\org\hdrhistogram\HdrHistogram\2.1.11\HdrHistogram-2.1.11.jar;D:\maven-repository\org\latencyutils\LatencyUtils\2.0.3\LatencyUtils-2.0.3.jar;D:\maven-repository\org\projectlombok\lombok\1.18.20\lombok-1.18.20.jar;D:\maven-repository\org\springframework\boot\spring-boot-starter-test\2.2.2.RELEASE\spring-boot-starter-test-2.2.2.RELEASE.jar;D:\maven-repository\org\springframework\boot\spring-boot-test\2.2.2.RELEASE\spring-boot-test-2.2.2.RELEASE.jar;D:\maven-repository\org\springframework\boot\spring-boot-test-autoconfigure\2.2.2.RELEASE\spring-boot-test-autoconfigure-2.2.2.RELEASE.jar;D:\maven-repository\com\jayway\jsonpath\json-path\2.4.0\json-path-2.4.0.jar;D:\maven-repository\net\minidev\json-smart\2.3\json-smart-2.3.jar;D:\maven-repository\net\minidev\accessors-smart\1.2\accessors-smart-1.2.jar;D:\maven-repository\org\ow2\asm\asm\5.0.4\asm-5.0.4.jar;D:\maven-repository\jakarta\xml\bind\jakarta.xml.bind-api\2.3.2\jakarta.xml.bind-api-2.3.2.jar;D:\maven-repository\jakarta\activation\jakarta.activation-api\1.2.1\jakarta.activation-api-1.2.1.jar;D:\maven-repository\org\junit\jupiter\junit-jupiter\5.5.2\junit-jupiter-5.5.2.jar;D:\maven-repository\org\junit\jupiter\junit-jupiter-api\5.5.2\junit-jupiter-api-5.5.2.jar;D:\maven-repository\org\opentest4j\opentest4j\1.2.0\opentest4j-1.2.0.jar;D:\maven-repository\org\junit\platform\junit-platform-commons\1.5.2\junit-platform-commons-1.5.2.jar;D:\maven-repository\org\junit\jupiter\junit-jupiter-params\5.5.2\junit-jupiter-params-5.5.2.jar;D:\maven-repository\org\junit\jupiter\junit-jupiter-engine\5.5.2\junit-jupiter-engine-5.5.2.jar;D:\maven-repository\org\junit\vintage\junit-vintage-engine\5.5.2\junit-vintage-engine-5.5.2.jar;D:\maven-repository\org\apiguardian\apiguardian-api\1.1.0\apiguardian-api-1.1.0.jar;D:\maven-repository\org\junit\platform\junit-platform-engine\1.5.2\junit-platform-engine-1.5.2.jar;D:\maven-repository\junit\junit\4.12\junit-4.12.jar;D:\maven-repository\org\mockito\mockito-junit-jupiter\3.1.0\mockito-junit-jupiter-3.1.0.jar;D:\maven-repository\org\assertj\assertj-core\3.13.2\assertj-core-3.13.2.jar;D:\maven-repository\org\hamcrest\hamcrest\2.1\hamcrest-2.1.jar;D:\maven-repository\org\mockito\mockito-core\3.1.0\mockito-core-3.1.0.jar;D:\maven-repository\net\bytebuddy\byte-buddy\1.10.4\byte-buddy-1.10.4.jar;D:\maven-repository\net\bytebuddy\byte-buddy-agent\1.10.4\byte-buddy-agent-1.10.4.jar;D:\maven-repository\org\objenesis\objenesis\2.6\objenesis-2.6.jar;D:\maven-repository\org\skyscreamer\jsonassert\1.5.0\jsonassert-1.5.0.jar;D:\maven-repository\com\vaadin\external\google\android-json\0.0.20131108.vaadin1\android-json-0.0.20131108.vaadin1.jar;D:\maven-repository\org\springframework\spring-core\5.2.2.RELEASE\spring-core-5.2.2.RELEASE.jar;D:\maven-repository\org\springframework\spring-jcl\5.2.2.RELEASE\spring-jcl-5.2.2.RELEASE.jar;D:\maven-repository\org\springframework\spring-test\5.2.2.RELEASE\spring-test-5.2.2.RELEASE.jar;D:\maven-repository\org\xmlunit\xmlunit-core\2.6.3\xmlunit-core-2.6.3.jar;D:\code\SpringCloud-hsp\code\e-commerce-center\e_commerce_center-common-api\target\classes com.example.springCloud.EurekaApplication . ____ _ __ _ _ /\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \ ( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \ \\/ ___)| |_)| | | | | || (_| | ) ) ) ) ' |____| .__|_| |_|_| |_\__, | / / / / =========|_|==============|___/=/_/_/_/ :: Spring Boot :: (v2.2.2.RELEASE) 2025-05-30 20:51:56.378 INFO 19288 --- [ main] c.example.springCloud.EurekaApplication : Starting EurekaApplication on DESKTOP-EP4100D with PID 19288 (D:\code\SpringCloud-hsp\code\e-commerce-center\e_commerce_eureka-server-9001\target\classes started by 86131 in D:\code\SpringCloud-hsp\code\e-commerce-center) 2025-05-30 20:51:56.380 INFO 19288 --- [ main] c.example.springCloud.EurekaApplication : No active profile set, falling back to default profiles: default 2025-05-30 20:51:56.718 WARN 19288 --- [ main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanDefinitionStoreException: Failed to process import candidates for configuration class [com.example.springCloud.EurekaApplication]; nested exception is java.lang.ArrayStoreException: sun.reflect.annotation.TypeNotPresentExceptionProxy 2025-05-30 20:51:56.726 INFO 19288 --- [ main] ConditionEvaluationReportLoggingListener : Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled. 2025-05-30 20:51:56.734 ERROR 19288 --- [ main] o.s.boot.SpringApplication : Application run failed org.springframework.beans.factory.BeanDefinitionStoreException: Failed to process import candidates for configuration class [com.example.springCloud.EurekaApplication]; nested exception is java.lang.ArrayStoreException: sun.reflect.annotation.TypeNotPresentExceptionProxy at org.springframework.context.annotation.ConfigurationClassParser.processImports(ConfigurationClassParser.java:597) ~[spring-context-5.2.2.RELEASE.jar:5.2.2.RELEASE] at org.springframework.context.annotation.ConfigurationClassParser.access$900(ConfigurationClassParser.java:109) ~[spring-context-5.2.2.RELEASE.jar:5.2.2.RELEASE] at org.springframework.context.annotation.ConfigurationClassParser$DeferredImportSelectorGroupingHandler.lambda$processGroupImports$1(ConfigurationClassParser.java:805) ~[spring-context-5.2.2.RELEASE.jar:5.2.2.RELEASE] at java.util.ArrayList.forEach(ArrayList.java:1259) ~[na:1.8.0_271] at org.springframework.context.annotation.ConfigurationClassParser$DeferredImportSelectorGroupingHandler.processGroupImports(ConfigurationClassParser.java:801) ~[spring-context-5.2.2.RELEASE.jar:5.2.2.RELEASE] at org.springframework.context.annotation.ConfigurationClassParser$DeferredImportSelectorHandler.process(ConfigurationClassParser.java:771) ~[spring-context-5.2.2.RELEASE.jar:5.2.2.RELEASE] at org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:188) ~[spring-context-5.2.2.RELEASE.jar:5.2.2.RELEASE] at org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:325) ~[spring-context-5.2.2.RELEASE.jar:5.2.2.RELEASE] at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry(ConfigurationClassPostProcessor.java:242) ~[spring-context-5.2.2.RELEASE.jar:5.2.2.RELEASE] at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanDefinitionRegistryPostProcessors(PostProcessorRegistrationDelegate.java:275) ~[spring-context-5.2.2.RELEASE.jar:5.2.2.RELEASE] at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:95) ~[spring-context-5.2.2.RELEASE.jar:5.2.2.RELEASE] at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:706) ~[spring-context-5.2.2.RELEASE.jar:5.2.2.RELEASE] at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:532) ~[spring-context-5.2.2.RELEASE.jar:5.2.2.RELEASE] at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:141) ~[spring-boot-2.2.2.RELEASE.jar:2.2.2.RELEASE] at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:747) [spring-boot-2.2.2.RELEASE.jar:2.2.2.RELEASE] at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397) [spring-boot-2.2.2.RELEASE.jar:2.2.2.RELEASE] at org.springframework.boot.SpringApplication.run(SpringApplication.java:315) [spring-boot-2.2.2.RELEASE.jar:2.2.2.RELEASE] at org.springframework.boot.SpringApplication.run(SpringApplication.java:1226) [spring-boot-2.2.2.RELEASE.jar:2.2.2.RELEASE] at org.springframework.boot.SpringApplication.run(SpringApplication.java:1215) [spring-boot-2.2.2.RELEASE.jar:2.2.2.RELEASE] at com.example.springCloud.EurekaApplication.main(EurekaApplication.java:17) [classes/:na] Caused by: java.lang.ArrayStoreException: sun.reflect.annotation.TypeNotPresentExceptionProxy at sun.reflect.annotation.AnnotationParser.parseClassArray(AnnotationParser.java:724) ~[na:1.8.0_271] at sun.reflect.annotation.AnnotationParser.parseArray(AnnotationParser.java:531) ~[na:1.8.0_271] at sun.reflect.annotation.AnnotationParser.parseMemberValue(AnnotationParser.java:355) ~[na:1.8.0_271] at sun.reflect.annotation.AnnotationParser.parseAnnotation2(AnnotationParser.java:286) ~[na:1.8.0_271] at sun.reflect.annotation.AnnotationParser.parseAnnotations2(AnnotationParser.java:120) ~[na:1.8.0_271] at sun.reflect.annotation.AnnotationParser.parseAnnotations(AnnotationParser.java:72) ~[na:1.8.0_271] at java.lang.Class.createAnnotationData(Class.java:3521) ~[na:1.8.0_271] at java.lang.Class.annotationData(Class.java:3510) ~[na:1.8.0_271] at java.lang.Class.getDeclaredAnnotations(Class.java:3477) ~[na:1.8.0_271] at org.springframework.core.annotation.AnnotationsScanner.getDeclaredAnnotations(AnnotationsScanner.java:461) ~[spring-core-5.2.2.RELEASE.jar:5.2.2.RELEASE] at org.springframework.core.annotation.AnnotationTypeMappings.addMetaAnnotationsToQueue(AnnotationTypeMappings.java:85) ~[spring-core-5.2.2.RELEASE.jar:5.2.2.RELEASE] at org.springframework.core.annotation.AnnotationTypeMappings.addAllMappings(AnnotationTypeMappings.java:79) ~[spring-core-5.2.2.RELEASE.jar:5.2.2.RELEASE] at org.springframework.core.annotation.AnnotationTypeMappings.<init>(AnnotationTypeMappings.java:68) ~[spring-core-5.2.2.RELEASE.jar:5.2.2.RELEASE] at org.springframework.core.annotation.AnnotationTypeMappings.<init>(AnnotationTypeMappings.java:46) ~[spring-core-5.2.2.RELEASE.jar:5.2.2.RELEASE] at org.springframework.core.annotation.AnnotationTypeMappings$Cache.createMappings(AnnotationTypeMappings.java:253) ~[spring-core-5.2.2.RELEASE.jar:5.2.2.RELEASE] at java.util.concurrent.ConcurrentMap.computeIfAbsent(ConcurrentMap.java:324) ~[na:1.8.0_271] at org.springframework.core.annotation.AnnotationTypeMappings$Cache.get(AnnotationTypeMappings.java:249) ~[spring-core-5.2.2.RELEASE.jar:5.2.2.RELEASE] at org.springframework.core.annotation.AnnotationTypeMappings.forAnnotationType(AnnotationTypeMappings.java:206) ~[spring-core-5.2.2.RELEASE.jar:5.2.2.RELEASE] at org.springframework.core.annotation.AnnotationTypeMappings.forAnnotationType(AnnotationTypeMappings.java:188) ~[spring-core-5.2.2.RELEASE.jar:5.2.2.RELEASE] at org.springframework.core.annotation.AnnotationTypeMappings.forAnnotationType(AnnotationTypeMappings.java:175) ~[spring-core-5.2.2.RELEASE.jar:5.2.2.RELEASE] at org.springframework.core.annotation.TypeMappedAnnotation.of(TypeMappedAnnotation.java:636) ~[spring-core-5.2.2.RELEASE.jar:5.2.2.RELEASE] at org.springframework.core.annotation.MergedAnnotation.of(MergedAnnotation.java:596) ~[spring-core-5.2.2.RELEASE.jar:5.2.2.RELEASE] at org.springframework.core.type.classreading.MergedAnnotationReadingVisitor.visitEnd(MergedAnnotationReadingVisitor.java:96) ~[spring-core-5.2.2.RELEASE.jar:5.2.2.RELEASE] at org.springframework.asm.ClassReader.readElementValues(ClassReader.java:2775) ~[spring-core-5.2.2.RELEASE.jar:5.2.2.RELEASE] at org.springframework.asm.ClassReader.accept(ClassReader.java:572) ~[spring-core-5.2.2.RELEASE.jar:5.2.2.RELEASE] at org.springframework.asm.ClassReader.accept(ClassReader.java:400) ~[spring-core-5.2.2.RELEASE.jar:5.2.2.RELEASE] at org.springframework.core.type.classreading.SimpleMetadataReader.<init>(SimpleMetadataReader.java:50) ~[spring-core-5.2.2.RELEASE.jar:5.2.2.RELEASE] at org.springframework.core.type.classreading.SimpleMetadataReaderFactory.getMetadataReader(SimpleMetadataReaderFactory.java:103) ~[spring-core-5.2.2.RELEASE.jar:5.2.2.RELEASE] at org.springframework.boot.type.classreading.ConcurrentReferenceCachingMetadataReaderFactory.createMetadataReader(ConcurrentReferenceCachingMetadataReaderFactory.java:86) ~[spring-boot-2.2.2.RELEASE.jar:2.2.2.RELEASE] at org.springframework.boot.type.classreading.ConcurrentReferenceCachingMetadataReaderFactory.getMetadataReader(ConcurrentReferenceCachingMetadataReaderFactory.java:73) ~[spring-boot-2.2.2.RELEASE.jar:2.2.2.RELEASE] at org.springframework.core.type.classreading.SimpleMetadataReaderFactory.getMetadataReader(SimpleMetadataReaderFactory.java:81) ~[spring-core-5.2.2.RELEASE.jar:5.2.2.RELEASE] at org.springframework.context.annotation.ConfigurationClassParser.asSourceClass(ConfigurationClassParser.java:686) ~[spring-context-5.2.2.RELEASE.jar:5.2.2.RELEASE] at org.springframework.context.annotation.ConfigurationClassParser$SourceClass.getMemberClasses(ConfigurationClassParser.java:977) ~[spring-context-5.2.2.RELEASE.jar:5.2.2.RELEASE] at org.springframework.context.annotation.ConfigurationClassParser.processMemberClasses(ConfigurationClassParser.java:347) ~[spring-context-5.2.2.RELEASE.jar:5.2.2.RELEASE] at org.springframework.context.annotation.ConfigurationClassParser.doProcessConfigurationClass(ConfigurationClassParser.java:266) ~[spring-context-5.2.2.RELEASE.jar:5.2.2.RELEASE] at org.springframework.context.annotation.ConfigurationClassParser.processConfigurationClass(ConfigurationClassParser.java:245) ~[spring-context-5.2.2.RELEASE.jar:5.2.2.RELEASE] at org.springframework.context.annotation.ConfigurationClassParser.processImports(ConfigurationClassParser.java:587) ~[spring-context-5.2.2.RELEASE.jar:5.2.2.RELEASE] ... 19 common frames omitted Process finished with exit code 1
05-31
(mp3d) dyj123456@dyj:/media/dyj123456/Linux/Matterport3D/Matterport3DSimulator$ cd Matterport3DSimulator mkdir build && cd build cmake -DEGL_RENDERING=ON -DPYTHON_EXECUTABLE=$(which python) .. make bash: cd: Matterport3DSimulator: 没有那个文件或目录 -- The CXX compiler identification is GNU 11.4.0 -- Detecting CXX compiler ABI info -- Detecting CXX compiler ABI info - done -- Check for working CXX compiler: /usr/bin/c++ - skipped -- Detecting CXX compile features -- Detecting CXX compile features - done CMake Deprecation Warning at CMakeLists.txt:2 (cmake_minimum_required): Compatibility with CMake < 2.8.12 will be removed from a future version of CMake. Update the VERSION argument <min> value or use a ...<max> suffix to tell CMake that the project does not need compatibility with older versions. -- Found OpenCV: /usr/local (found version "3.4.15") -- Found PkgConfig: /usr/bin/pkg-config (found version "0.29.2") -- Found OpenMP_CXX: -fopenmp (found version "4.5") -- Found OpenMP: TRUE (found version "4.5") -- Checking for module 'jsoncpp' -- Found jsoncpp, version 1.9.5 -- Found OpenGL: /usr/lib/x86_64-linux-gnu/libOpenGL.so found components: OpenGL EGL -- Checking for module 'epoxy' -- Found epoxy, version 1.5.10 -- Found PythonInterp: /home/dyj123456/miniconda3/envs/mp3d/bin/python (found version "3.9.25") -- Found PythonLibs: /home/dyj123456/miniconda3/envs/mp3d/lib/libpython3.9.so -- Performing Test HAS_CPP14_FLAG -- Performing Test HAS_CPP14_FLAG - Success -- pybind11 v2.2.1 -- Found PythonInterp: /home/dyj123456/miniconda3/envs/mp3d/bin/python (found suitable version "3.9.25", minimum required is "3") /home/dyj123456/miniconda3/envs/mp3d/bin/python CMake Warning (dev) at /usr/share/cmake-3.22/Modules/FindPackageHandleStandardArgs.cmake:438 (message): The package name passed to `find_package_handle_standard_args` (NUMPY) does not match the name of the calling package (NumPy). This can lead to problems in calling code that expects `find_package` result variables (e.g., `_FOUND`) to follow a certain pattern. Call Stack (most recent call first): cmake/Modules/FindNumPy.cmake:106 (find_package_handle_standard_args) CMakeLists.txt:70 (find_package) This warning is for project developers. Use -Wno-dev to suppress it. -- Could NOT find NUMPY (missing: NUMPY_INCLUDES) -- Performing Test HAS_FLTO -- Performing Test HAS_FLTO - Success -- LTO enabled -- Configuring done -- Generating done -- Build files have been written to: /media/dyj123456/Linux/Matterport3D/Matterport3DSimulator/build [ 9%] Building CXX object CMakeFiles/MatterSim.dir/src/lib/MatterSim.cpp.o [ 18%] Building CXX object CMakeFiles/MatterSim.dir/src/lib/NavGraph.cpp.o [ 27%] Building CXX object CMakeFiles/MatterSim.dir/src/lib/Benchmark.cpp.o [ 36%] Building CXX object CMakeFiles/MatterSim.dir/src/lib/cbf.cpp.o [ 45%] Linking CXX shared library libMatterSim.so [ 45%] Built target MatterSim [ 54%] Building CXX object CMakeFiles/tests.dir/src/test/main.cpp.o In file included from /usr/include/signal.h:328, from /media/dyj123456/Linux/Matterport3D/Matterport3DSimulator/include/Catch.hpp:6456, from /media/dyj123456/Linux/Matterport3D/Matterport3DSimulator/src/test/main.cpp:15: /media/dyj123456/Linux/Matterport3D/Matterport3DSimulator/include/Catch.hpp:6631:45: error: size of array ‘altStackMem’ is not an integral constant-expression 6631 | char FatalConditionHandler::altStackMem[SIGSTKSZ] = {}; | ^~~~~~~~ make[2]: *** [CMakeFiles/tests.dir/build.make:76:CMakeFiles/tests.dir/src/test/main.cpp.o] 错误 1 make[1]: *** [CMakeFiles/Makefile2:132:CMakeFiles/tests.dir/all] 错误 2 make: *** [Makefile:91:all] 错误 2
最新发布
12-07
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值