Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- struct Node * tree_add (struct Node * tree, Data x) {
- if (tree == NULL) {
- struct Node* newTree = (struct Node*)calloc(1, sizeof(struct Node));
- newTree->left = NULL;
- newTree->right = NULL;
- newTree->val = x;
- return newTree;
- }
- if (x < tree->val)
- tree->left = tree_add(tree->left, x);
- if (x > tree->val)
- tree->right = tree_add(tree->right, x);
- return tree;
- }
- void tree_print (struct Node * tree) {
- if (tree == NULL)
- return;
- tree_print(tree->left);
- printf("%d ", tree->val);
- tree_print(tree->right);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement