我正在开发一个二叉树的 C 库,我想知道如何保存树根的值以便稍后在函数中显示它。
我的树结构:
struct Node {
int value;
struct Node *left;
struct Node *right;
};
typedef struct Node TNode;
typedef struct Node *binary_tree;
二叉树根使用 3 值初始化,如下所示:
来电者:
tree = NewBinaryTree(3);
NewBinaryTree 方法:
binary_tree NewBinaryTree(int value_root) {
binary_tree newRoot = malloc(sizeof(TNode));
if (newRoot) {
newRoot->value = value_root;
newRoot->left = NULL;
newRoot->right = NULL;
}
return newRoot;
}
基本上,我希望能够执行一个函数,即使在向二叉树添加元素之后,也只显示 value_root 函数,并且仍然能够显示 value_root 值。这可能非常基本,但我正在学习 C,但我不是当然。
谢谢
最佳答案
在调用者中:printf( "%d\n", tree->value )
– user3386109
关于c - 将 C 二叉树根值保存在变量中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41047400/