A collection of C programs for learning and implementing binary tree operations, including traversal, insertion, deletion, and validation. Ideal for understanding fundamental data structures and algorithms in C programming.
Write a function that inserts a node as the right-child of another node
Prototype: binary_tree_t binary_tree_insert_right(binary_tree_t parent, int value);
Where parent is a pointer to the node to insert the right-child in
And value is the value to store in the new node
Your function must return a pointer to the created node, or NULL on failure or if parent is NULL
If parent already has a right-child, the new node must take its place, and the old right-child must be set as the right-child of the new node.
alex@/tmp/binary_trees$ cat 2-main.c
include
include
include "binary_trees.h"
/**
main - Entry point
Return: Always 0 (Success)
/
int main(void)
{
binary_tree_t root;
Write a function that inserts a node as the right-child of another node
Prototype: binary_tree_t binary_tree_insert_right(binary_tree_t parent, int value); Where parent is a pointer to the node to insert the right-child in And value is the value to store in the new node Your function must return a pointer to the created node, or NULL on failure or if parent is NULL If parent already has a right-child, the new node must take its place, and the old right-child must be set as the right-child of the new node. alex@/tmp/binary_trees$ cat 2-main.c
include
include
include "binary_trees.h"
/**
Return: Always 0 (Success) / int main(void) { binary_tree_t root;
root = binary_tree_node(NULL, 98); root->left = binary_tree_node(root, 12); root->right = binary_tree_node(root, 402); binary_tree_print(root); printf("\n"); binary_tree_insert_right(root->left, 54); binary_tree_insert_right(root, 128); binary_tree_print(root); return (0); } alex@/tmp/binary_trees$ gcc -Wall -Wextra -Werror -pedantic binary_tree_print.c 2-main.c 2-binary_tree_insert_right.c 0-binary_tree_node.c -o 2-right alex@/tmp/binary_trees$ ./2-right .--(098)--. (012) (402)
.-------(098)--. (012)--. (128)--. (054) (402) alex@/tmp/binary_trees$