commit 211a3863e6d76ace6b2a18bbad70ea50220c1051 parent 8230d59262ba83dec80393202eb39d74fba932b3 Author: Plat <plat@stellar-nexus.ru> Date: Sat, 18 Oct 2025 20:17:54 +0000 Added init and add functions Diffstat:
| A | parser.c | | | 32 | ++++++++++++++++++++++++++++++++ |
1 file changed, 32 insertions(+), 0 deletions(-)
diff --git a/parser.c b/parser.c @@ -0,0 +1,32 @@ +#include <stdlib.h> + +#include "util.h" + + +Node* +init(int val) +{ + Node *n = emalloc(sizeof(Node)); + + n->val = val; + n->left = NULL; + n->right = NULL; + + return n; +} + +void +add(int val, Node *root) +{ + if (val < root->val) { + if (n->left == NULL) + n->left = init(val); + else + add(val, root->left); + } else { + if (n->right == NULL) + n->right = init(val); + else + add(val, root->right); + } +}