Im working on a C library for binary tree, and Im wondering how I could save the value of the root of the tree to be able to display it later in a function.
My tree struct:
struct Node {
int value;
struct Node *left;
struct Node *right;
};
typedef struct Node TNode;
typedef struct Node *binary_tree;
The binary tree root is initialised with the 3 value like this:
caller:
tree = NewBinaryTree(3);
NewBinaryTree method:
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;
}
Basically I would like to be able to do a function that just display the value_root function even after adding elements to the binary tree and be able to still display the value_root value.This might be very basic but im learning C and im not sure.
thank you