首页
DreamJudge
院校信息
专业题库
模拟考试
机试真题
上岸课程
兑换中心
登录
注册
上岸
以下题解仅供学习参考使用。
抄袭、复制题解,以达到刷AC率/AC数量或其他目的的行为,在N诺是严格禁止的。
N诺非常重视学术诚信。此类行为将会导致您成为作弊者。具体细则请查看N诺社区规则。
emoji
2025年3月20日 21:04
二叉树遍历 题解:难点在于题目输入的字符串最后‘#’不够,导致没做完树
P1161
回复 0
|
赞 16
|
浏览 254
在这里借鉴了大佬们的全局变量想法,设置全局变量char s[100]和int a,主要作用是当输入 '\0'时,自动为没建好的树叶节点全部为NULL。 #include<iostream> #include<string> using namespace std; int a; char s[100]; typedef struct node{ char data; struct node *lchild,*rchild; }*BitTree; void visit(BitTree T){ if(T!=NULL)...
shiv15832
2025年3月18日 17:53
二叉树遍历 题解:整段输入如何传参?全局变量解答
P1161
回复 1
|
赞 11
|
浏览 263
先序遍历如何构建二叉树可以看题目1109题解:https://noobdream.com/post/377728/ 本题的问题是如何整个字符串输入的情况下传递参数,如果能将一整段的输入转化为单个的字符放到我们构建二叉树的函数里就很简单了。但经典的for循环能做到吗?显然不行,因为树的构建一般是基于递归,递归本身在循环那么如何将递归套在for循环里面?这条路显然是不可取的。那么我们设置一个全局变量i指向字符串的下标,每次构建节点之后i++不就可以了吗。 代码:#include<bits/stdc++.h> using namespace std; typedef...
山崎友希
2025年3月10日 20:42
二叉树遍历 题解:
P1161
回复 0
|
赞 28
|
浏览 457
#include <stdio.h> typedef struct erchashu{//创建一个结构体 它叫erchashu char data;//数据域 struct erchashu *Lchild,*Rchild; }TNode,*BTtree; int i=0;//设立全局变量i //它的改变 其他所有人都可以看得到 int CreateBTtree(BTtree &T, char s1[]){//先序遍历创...
Txh
2025年3月9日 12:12
二叉树遍历 题解:
P1161
回复 1
|
赞 6
|
浏览 278
求大神指导 为什么会超时 如何修改 #include<stdio.h> #include<stdlib.h> struct treenode{ char data; struct treenode *left; struct treenode *right; }; void func(struct treenode *root); struct treenode *creat(); int main(){ ...
x1ngchui
2025年3月7日 16:29
二叉树遍历 题解:
P1161
回复 0
|
赞 5
|
浏览 254
#include <stdio.h> #include <string.h> #include <stdlib.h> struct node { char code; struct node* left; struct node* right; }; struct node* build_tree(const char* str, int* pindex, int end) { if (*pindex >= end) return NULL; char code = s...
西电机试专家
2025年2月28日 11:36
二叉树遍历 题解:新手题解,勿喷
P1161
回复 1
|
赞 16
|
浏览 427
#include<bits/stdc++.h> using namespace std; typedef struct node{ char data; struct node *left,*right; }*BiTree; int cur=0;//全局变量:记录当前遍历到的字符串下标 (不可使用index) void creattree(BiTree &T,string str) {//建树 &nbs...
Chen沧月有泪
2025年2月20日 13:10
二叉树遍历 题解:
P1161
回复 0
|
赞 9
|
浏览 383
#include<iostream> #include<string> struct TreeNode { char ch; TreeNode* lchild; TreeNode* rchild; }; std::string s = ""; int length = 0; void CreateTree(TreeNode*& root) { if (length...
wut to hust
2025年2月4日 20:08
请问一下,我这个为什么报运行时错误呀,本地ide运行测试用例是对的
P1161
回复 1
|
赞 7
|
浏览 427
#include <bits/stdc++.h> using namespace std; typedef struct node { char data; node* l, * r; }*tree; void create(tree& t) { char c; cin >> c; if (c == '#') t = nullptr; ...
zcq107
2025年1月14日 20:39
二叉树遍历 题解:
P1161
回复 2
|
赞 14
|
浏览 695
为何这么写,测试用例可以在本地ide正确运行,但是在平台上现实runtime,没有检查出问题,求解答 #include<bits/stdc++.h> using namespace std; struct btnode{ char data; btnode* lchild; btnode* rchild; }; string s; int len; btnode* create(){ char c; c = s[len++]; if(c == '#') return nullptr; ...
ccccccyes
2024年9月9日 17:05
二叉树遍历 题解:
P1161
回复 0
|
赞 39
|
浏览 1.3k
// // #include <iostream> using namespace std; typedef struct Node{ char ch; struct Node *lchild,*rchild; } *node; string str; int len; void createBitTree(node &n){ if(len == str.size()) return; char c = str[len++]; if(c == '#') n = NULL; //->是可以给...
1
2
3
题目
二叉树遍历
题解数量
29
发布题解
在线答疑
热门题解
1
二叉树遍历 题解:
2
二叉树遍历 题解:
3
套用教材模板,同时解决RunTime ERROR
4
二叉树遍历 题解:新手题解,勿喷
5
二叉树遍历 题解:难点在于题目输入的字符串最后‘#’不够,导致没做完树,没有返回
6
二叉树遍历 题解:c++注意超时问题
7
二叉树遍历 题解:
8
二叉树遍历 题解:c++
9
二叉树遍历 题解:整段输入如何传参?全局变量解答
10
1161 二叉树遍历 (8月8日,测试数据已修复,能AC)