代码未在联机编译器上显示结果
code not showing result on online compiler
我试图为树的垂直顺序遍历编写代码,我的代码在 code::blocks 上打印结果,但是当在 geekforgeeks 在线 ide 中运行相同的东西时,它不会打印结果。为什么要这样做?
void getvert(Node* root,int hd,map<int,vector<int>>m){
if(root==NULL)return;
m[hd].push_back(root->data);
getvert(root->left,hd-1,m);
getvert(root->right,hd+1,m);
}
void verticalOrder(Node *root)
{
map<int,vector<int>>m;
int hd=0;
getvert(root,hd,m);
auto it=m.begin();
for(;it!=m.end();it++)
{
for (int i=0; i<it->second.size(); ++i)
cout<<it->second[i];
cout<<endl;
}
}
函数getvert
接受最后一个参数m
作为值。在函数中对它所做的更改将针对对象的本地副本进行。因此,您看不到任何更改verticalOrder
.
更改getvert
,使其接受m
作为引用。
void getvert(Node* root,int hd, map<int,vector<int>>& m) // Need reference argument
{
...
}
相关文章:
- 代码未在联机编译器上显示结果
- 我的循环超时并且不显示结果
- C 可执行文件从浏览器下载而不是显示结果
- 如果满足嵌套条件,则计算结果未显示结果C
- 使用 std::async 准备好后立即显示结果
- if, else if, else 函数未准确显示结果
- C++:如何在控制台窗口中显示结果
- VIM:执行复杂文件类型的脚本和显示结果
- 根据标准对结构向量进行排序,然后显示结果
- c++将var从一个函数传递到另一个函数,然后在主函数中显示结果
- 当结果超过 100 时,程序不显示结果
- 对输入'age'名称进行排序,然后显示结果
- 代码可以运行,但不在 Eclipse 中显示结果。
- 将代码C++到 MIPS 中,MIPS 中的代码运行时没有错误消息,但不显示结果
- 为什么使用 scanf() 时显示结果有延迟
- 如何使用信号和插槽从qt表单中获取id,然后在链表中搜索它并使用另一个表单显示结果
- C++不显示结果
- 最长公共子序列没有显示结果
- C++需要在Main()调试中显示结果的帮助
- C/C++读取UART端口并显示结果