c++-这段代码输出的root是root->data==item的那个root吗,不是的话是哪个root

问题描述

这段代码输出的root是root->data==item的那个root吗,不是的话是哪个root

//查找二叉树中值为item的结点
BTNode *FindBTree(BTNode *root, DataType item)
{
if (root != NULL)
{
FindBTree(root->left, item);
FindBTree(root->right, item);
if (root->data == item)
{
return root;
}
}
}

解决方案

新人求带,感觉好复杂的样子,好吧我努力

解决方案二:

返回的是最后找到item的root,除非return在if语句外面做最终返回才是原来的root。

解决方案三:

因为递归是一个压栈的过程,我想只要你能够深入的理解递归的过程(函数压栈)的话,我觉得你肯定知道结果...

解决方案四:

是,不过是最后一次找到的那个root(如果有多个的话),

解决方案五:

Android中Root权限获取的简单代码(3)

时间: 2024-08-30 02:15:31

c++-这段代码输出的root是root->data==item的那个root吗,不是的话是哪个root的相关文章

这段代码输出保存在数据库中的json格式数据怎么用java代码在前端显示出来

问题描述 这段代码输出保存在数据库中的json格式数据怎么用java代码在前端显示出来 public class SaveHotKeySkillReq extends CommandBase { @Resource //数据库操作 private EntityManager em; protected void execute() throws GMessageException { CRequesthotKeyChange msg = pak.readMsg(CRequesthotKeyCha

这段代码输出的网页为何是乱码

问题描述 usingSystem;usingSystem.Collections.Generic;usingSystem.Text;usingSystem.Net;usingSystem.IO;namespacethief{classProgram{staticvoidMain(string[]args){try{WebClientMyWebClient=newWebClient();MyWebClient.Credentials=CredentialCache.DefaultCredentia

c语言-这段代码为什么没有输出

问题描述 这段代码为什么没有输出 #include "stdio.h" #include "math.h" #include "time.h" int main() { int n=100,a,b,c; for(n=100; n<1000; n++) { a = n/100; b = n/10%10; c = n%10; if(n == a*a*a + b*b*b + c*c*c) printf("%d ",n); el

c++-为什么这段代码循环输出的数组少了第一个元素且多出了一个随机数?

问题描述 为什么这段代码循环输出的数组少了第一个元素且多出了一个随机数? 输入一些非负实数 用数组输出这些数 求平均数并输出(输入负数时报错并退出重新输入,输入回车时执行下一步操作) #include using namespace std; int main() { int i,j,k; double a[100],sum=0,avr; part1: cout<<"输入数字"< j=0,k=0; for (i=0;getchar()!='n';i++) { cin&

c++-为什么这段代码中对象rectangle的各个成员函数输出的值是对的,而box的却都是错的

问题描述 为什么这段代码中对象rectangle的各个成员函数输出的值是对的,而box的却都是错的 #include using namespace std; class rectangle { protected: double length,width,l,w; public: void setlength(); void getlength(); void setwidth(); void getwidth(); double area(); double perimeter(); dou

继承-这段代码的输出结果能不能给解释解释?

问题描述 这段代码的输出结果能不能给解释解释? public class A { public A() {init();} protected void init() {} static class B extends A{ int i,j=999; protected void init() { System.out.println("此时A的构造方法正在调用此方法:i的值为:"+i+",j的值为:"+j); i=888; j=111; } } public st

请问这段代码为什么输出null,求大神解答程序执行的顺序?

问题描述 请问这段代码为什么输出null,求大神解答程序执行的顺序? public class xieCheng { private String baseName="Base"; public xieCheng(){ this.callName(); } public void callName(){ System.out.println(baseName); } } public class Sub extends xieCheng { private String baseNam

能解释下下面这段代码的含义,以及为什么会这样输出吗?(没有金币了,拜托了)

问题描述 能解释下下面这段代码的含义,以及为什么会这样输出吗?(没有金币了,拜托了) package com.think_in_java_Chapter12; import java.io.*; import java.util.logging.Logger; class LoggingException extends Exception{ private static Logger logger = Logger.getLogger("LoggingException"); pub

verilog-这段代码是计算两个数相除,不能输出正确结果,求问错在哪里

问题描述 这段代码是计算两个数相除,不能输出正确结果,求问错在哪里 module divide_16bits(op1,op2,result ); input [15:0] op1; input [15:0] op2; output reg [15:0] result; reg error; integer p,q,r; reg [15:0] temp; reg [15:0] add_result; always @(op1 or op2) begin assign error = ~{|{op2