C++ Visual Studio中的错误结果

C++ Visual Studio中的错误结果,c++,visual-studio,binary-search-tree,codeblocks,C++,Visual Studio,Binary Search Tree,Codeblocks,我以前从未遇到过这种错误。当我在CodeBlock中编译时,我的代码运行得很好,但当我将代码复制到VS(2015社区)中时,它只显示了两个数字。(我正在打印一棵二叉树) 这是二进制搜索树的代码,它在代码块中运行良好,但在VisualStudio中不起作用 #include<iostream> using namespace std; struct node { int data; int balance_factor; node* left_linker;

我以前从未遇到过这种错误。当我在CodeBlock中编译时,我的代码运行得很好,但当我将代码复制到VS(2015社区)中时,它只显示了两个数字。(我正在打印一棵二叉树)

这是二进制搜索树的代码,它在代码块中运行良好,但在VisualStudio中不起作用

#include<iostream>
using namespace std;
struct node
{
    int data;
    int balance_factor;
    node* left_linker;
    node* right_linker;
};

struct binary_tree
{
    node* root;
};

void init_tree(binary_tree& in_tree);
node* create_new_node(int data);
void insert_node(int in_data,binary_tree& in_tree);
node* insert_recursively(int in_data,node* in_root);
bool tree_empty(binary_tree& in_tree);
void print_tree_from_root(node* in_root);

int main(int argc,char* argv[])
{
    binary_tree tree_1;
    init_tree(tree_1);
    insert_node(10,tree_1);
    insert_node(30,tree_1);
    insert_node(40,tree_1);
    insert_node(20,tree_1);
    insert_node(50,tree_1);
    print_tree_from_root(tree_1.root);
}
void init_tree(binary_tree& in_tree)
{
    in_tree.root = NULL;
}
node* create_new_node(int data)
{
    node* temp = new node;
    temp->data = data;
    temp->left_linker = NULL;
    temp->right_linker = NULL;
    return temp;
}
void insert_node(int in_data,binary_tree& in_tree)
{
    if(tree_empty(in_tree))
    {
        in_tree.root = create_new_node(in_data);
    }
    else
    {
        insert_recursively(in_data,in_tree.root);
    }
}

node* insert_recursively(int in_data,node* in_root)
{
    if(in_root == 0)
    {
        in_root = create_new_node(in_data);
        return in_root;
    }
    else
    {
        if(in_data > in_root->data)
        {
            in_root->right_linker = insert_recursively(in_data,in_root->right_linker);
        }
        else if(in_data < in_root->data)
        {
            in_root->left_linker = insert_recursively(in_data,in_root->left_linker);
        }
    }
}

bool tree_empty(binary_tree& in_tree)
{
    if(in_tree.root == 0)
        return true;
    return false;
}

void print_tree_from_root(node* in_root)
{
    if(in_root == NULL)
    {
        return;
    }
    else
    {
        cout<<in_root->data<<endl;
        print_tree_from_root(in_root->left_linker);
        print_tree_from_root(in_root->right_linker);
    }
}
#包括
使用名称空间std;
结构节点
{
int数据;
国际收支平衡系数;
节点*左链接器;
节点*右链接器;
};
结构二叉树
{
节点*根;
};
void init_树(二叉树和in_树);
节点*创建新节点(int数据);
void insert_节点(int in_数据、二进制_树和in_树);
节点*递归插入_(int在_数据中,节点*在_根中);
布尔树为空(二叉树和in树);
从\u根(节点*在\u根中)作废打印\u树\u;
int main(int argc,char*argv[])
{
二叉树;
初始树(树1);
插入_节点(10,树_1);
插入_节点(30,树_1);
插入_节点(40,树_1);
插入_节点(20,树_1);
插入_节点(50,树_1);
从根(树1.root)打印树;
}
void init_树(二叉树和in_树)
{
in_tree.root=NULL;
}
节点*创建新节点(整数数据)
{
node*temp=新节点;
温度->数据=数据;
temp->left_linker=NULL;
临时->右链接器=NULL;
返回温度;
}
void insert_节点(int in_数据、二进制_树和in_树)
{
if(树中为空)
{
in_tree.root=创建新节点(in_数据);
}
其他的
{
递归地插入_(在_数据中,在_tree.root中);
}
}
节点*递归插入(数据中的int,根中的节点*)
{
if(in_root==0)
{
in_root=创建新节点(in_data);
以_根返回;
}
其他的
{
如果(在\u数据>在\u根->数据中)
{
在\u根->右\u链接器中=递归插入\u(在\u数据中,在\u根->右\u链接器中);
}
else if(in_datadata)
{
在\u根->左\u链接器中=递归插入\u(在\u数据中,在\u根->左\u链接器中);
}
}
}
布尔树为空(二叉树和in树)
{
if(in_tree.root==0)
返回true;
返回false;
}
从\u根(节点*在\u根中)作废打印\u树\u
{
if(in_root==NULL)
{
返回;
}
其他的
{

cout
insert\u递归
进入
else
块时不返回值,但您将返回的值(垃圾)存储在
右链接器
左链接器

请注意,编译器会发出相应的警告:

警告C4715:“递归插入”:并非所有控制路径都返回值


请不要将代码作为图片来张贴。创建一个并将其作为文本。不要忘记用语言标记(我猜C++)。实际上,这不是所有的代码,问题是编辑器,在VisualStudio中,上面的结果不正确,你真的认为Visual Studio有错,我们不能帮助你。我们只能帮助你的代码。但是,错误是在你的代码中。它是C++还是C?我编辑了这个问题来删除图像和INS。请插入实际代码。@nvoigt(作为对第一条注释的注释)我解决了问题,谢谢,但我仍然不明白为什么代码块会打印所有值