{"id":21755430,"url":"https://github.com/pericles001/binary_trees","last_synced_at":"2025-08-12T16:04:45.759Z","repository":{"id":108214144,"uuid":"460011640","full_name":"Pericles001/binary_trees","owner":"Pericles001","description":"In computer science, a binary tree is a tree data structure in which each node has at most two children, which are referred to as the left child and the right child. ...  This project is all about training oneself to work on various binary tree possibilities (creation of a root node/left-child/right-child, deletion and more over.)","archived":false,"fork":false,"pushed_at":"2022-02-18T13:39:17.000Z","size":80,"stargazers_count":4,"open_issues_count":0,"forks_count":6,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-20T09:57:55.935Z","etag":null,"topics":["binary-trees","data-structures"],"latest_commit_sha":null,"homepage":"","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Pericles001.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2022-02-16T13:17:09.000Z","updated_at":"2023-09-21T08:09:10.000Z","dependencies_parsed_at":"2024-04-21T08:00:26.517Z","dependency_job_id":null,"html_url":"https://github.com/Pericles001/binary_trees","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/Pericles001/binary_trees","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Pericles001%2Fbinary_trees","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Pericles001%2Fbinary_trees/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Pericles001%2Fbinary_trees/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Pericles001%2Fbinary_trees/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Pericles001","download_url":"https://codeload.github.com/Pericles001/binary_trees/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Pericles001%2Fbinary_trees/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":270091520,"owners_count":24525208,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-12T02:00:09.011Z","response_time":80,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["binary-trees","data-structures"],"created_at":"2024-11-26T09:18:00.663Z","updated_at":"2025-08-12T16:04:45.739Z","avatar_url":"https://github.com/Pericles001.png","language":"C","readme":"0x1D. C - Binary trees\n======================\n\n-   By Alexandre Gautier\n-   Weight: 5\n\nResources\n---------\n\n**Read or watch**:\n\n-   [Binary tree](https://alx-intranet.hbtn.io/rltoken/1F2x42-8vUbOmU4L1C1KMg \"Binary tree\") (*note the first line: `Not to be confused with B-tree.`*)\n-   [Data Structure and Algorithms - Tree](https://alx-intranet.hbtn.io/rltoken/QmcTMCkQyrgMjrqoWxYdhw \"Data Structure and Algorithms - Tree\")\n-   [Tree Traversal](https://alx-intranet.hbtn.io/rltoken/nMxoYQdZR_guroan8JeqBQ \"Tree Traversal\")\n-   [Binary Search Tree](https://alx-intranet.hbtn.io/rltoken/qO5dBlMnYJzbaWG3xVpcnQ \"Binary Search Tree\")\n-   [Data structures: Binary Tree](https://alx-intranet.hbtn.io/rltoken/BeyJ2gjlE7_djwRiDyeHig \"Data structures: Binary Tree\")\n\nLearning Objectives\n-------------------\n\nAt the end of this project, you are expected to be able to [explain to anyone](https://alx-intranet.hbtn.io/rltoken/rDjGcLNoVZsZG1Br0UbX6A \"explain to anyone\"), **without the help of Google**:\n\n### General\n\n-   What is a binary tree\n-   What is the difference between a binary tree and a Binary Search Tree\n-   What is the possible gain in terms of time complexity compared to linked lists\n-   What are the depth, the height, the size of a binary tree\n-   What are the different traversal methods to go through a binary tree\n-   What is a complete, a full, a perfect, a balanced binary tree\n\nRequirements\n------------\n\n### General\n\n-   Allowed editors: `vi`, `vim`, `emacs`\n-   All your files will be compiled on Ubuntu 20.04 LTS using gcc, using the options -Wall -Werror -Wextra -pedantic -std=gnu89\n-   All your files should end with a new line\n-   A `README.md` file, at the root of the folder of the project, is mandatory\n-   Your code should use the `Betty` style. It will be checked using [betty-style.pl](https://github.com/holbertonschool/Betty/blob/master/betty-style.pl \"betty-style.pl\") and [betty-doc.pl](https://github.com/holbertonschool/Betty/blob/master/betty-doc.pl \"betty-doc.pl\")\n-   You are not allowed to use global variables\n-   No more than 5 functions per file\n-   You are allowed to use the standard library\n-   In the following examples, the `main.c` files are shown as examples. You can use them to test your functions, but you don't have to push them to your repo (if you do we won't take them into account). We will use our own `main.c` files at compilation. Our `main.c` files might be different from the one shown in the examples\n-   The prototypes of all your functions should be included in your header file called `binary_trees.h`\n-   Don't forget to push your header file\n-   All your header files should be include guarded\n\n### GitHub\n\n**There should be one project repository per group. If you clone/fork/whatever a project repository with the same name before the second deadline, you risk a 0% score.**\n\nMore Info\n---------\n\n### Data structures\n\nPlease use the following data structures and types for binary trees. Don't forget to include them in your header file.\n\n#### Basic Binary Tree\n\n```\n/**\n * struct binary_tree_s - Binary tree node\n *\n * @n: Integer stored in the node\n * @parent: Pointer to the parent node\n * @left: Pointer to the left child node\n * @right: Pointer to the right child node\n */\nstruct binary_tree_s\n{\n    int n;\n    struct binary_tree_s *parent;\n    struct binary_tree_s *left;\n    struct binary_tree_s *right;\n};\n\ntypedef struct binary_tree_s binary_tree_t;\n\n```\n\n#### Binary Search Tree\n\n```\ntypedef struct binary_tree_s bst_t;\n\n```\n\n#### AVL Tree\n\n```\ntypedef struct binary_tree_s avl_t;\n\n```\n\n#### Max Binary Heap\n\n```\ntypedef struct binary_tree_s heap_t;\n\n```\n\n**Note:** For tasks 0 to 23 (included), you have to deal with simple binary trees. They are not BSTs, thus they don't follow any kind of rule.\n\n### Print function\n\nTo match the examples in the tasks, you are given [this function](https://github.com/holbertonschool/0x1C.c \"this function\")\n\nThis function is used only for visualization purposes. You don't have to push it to your repo. It may not be used during the correction\n\nTasks\n-----\n\n### 0\\. New node\n\nmandatory\n\nWrite a function that creates a binary tree node\n\n-   Prototype: `binary_tree_t *binary_tree_node(binary_tree_t *parent, int value);`\n-   Where `parent` is a pointer to the parent node of the node to create\n-   And `value` is the value to put in the new node\n-   When created, a node does not have any child\n-   Your function must return a pointer to the new node, or `NULL` on failure\n\n```\nalex@/tmp/binary_trees$ cat 0-main.c\n#include \u003cstdlib.h\u003e\n#include \"binary_trees.h\"\n\n/**\n * main - Entry point\n *\n * Return: Always 0 (Success)\n */\nint main(void)\n{\n    binary_tree_t *root;\n\n    root = binary_tree_node(NULL, 98);\n\n    root-\u003eleft = binary_tree_node(root, 12);\n    root-\u003eleft-\u003eleft = binary_tree_node(root-\u003eleft, 6);\n    root-\u003eleft-\u003eright = binary_tree_node(root-\u003eleft, 16);\n\n    root-\u003eright = binary_tree_node(root, 402);\n    root-\u003eright-\u003eleft = binary_tree_node(root-\u003eright, 256);\n    root-\u003eright-\u003eright = binary_tree_node(root-\u003eright, 512);\n\n    binary_tree_print(root);\n    return (0);\n}\nalex@/tmp/binary_trees$ gcc -Wall -Wextra -Werror -pedantic binary_tree_print.c 0-main.c 0-binary_tree_node.c -o 0-node\nalex@/tmp/binary_trees$ ./0-node\n       .-------(098)-------.\n  .--(012)--.         .--(402)--.\n(006)     (016)     (256)     (512)\nalex@/tmp/binary_trees$\n\n```\n\n**Repo:**\n\n-   GitHub repository: `binary_trees`\n-   File: `0-binary_tree_node.c`\n\n Done? Help Check your code Get a sandbox\n\n### 1\\. Insert left\n\nmandatory\n\nWrite a function that inserts a node as the left-child of another node\n\n-   Prototype: `binary_tree_t *binary_tree_insert_left(binary_tree_t *parent, int value);`\n-   Where `parent` is a pointer to the node to insert the left-child in\n-   And `value` is the value to store in the new node\n-   Your function must return a pointer to the created node, or `NULL` on failure or if `parent` is `NULL`\n-   If `parent` already has a left-child, the new node must take its place, and the old left-child must be set as the left-child of the new node.\n\n```\nalex@/tmp/binary_trees$ cat 1-main.c\n#include \u003cstdlib.h\u003e\n#include \u003cstdio.h\u003e\n#include \"binary_trees.h\"\n\n/**\n * main - Entry point\n *\n * Return: Always 0 (Success)\n */\nint main(void)\n{\n    binary_tree_t *root;\n\n    root = binary_tree_node(NULL, 98);\n    root-\u003eleft = binary_tree_node(root, 12);\n    root-\u003eright = binary_tree_node(root, 402);\n    binary_tree_print(root);\n    printf(\"\\n\");\n    binary_tree_insert_left(root-\u003eright, 128);\n    binary_tree_insert_left(root, 54);\n    binary_tree_print(root);\n    return (0);\n}\nalex@/tmp/binary_trees$ gcc -Wall -Wextra -Werror -pedantic binary_tree_print.c 1-main.c 1-binary_tree_insert_left.c 0-binary_tree_node.c -o 1-left\nalex@/tmp/binary_trees$ ./1-left\n  .--(098)--.\n(012)     (402)\n\n       .--(098)-------.\n  .--(054)       .--(402)\n(012)          (128)\nalex@/tmp/binary_trees$\n\n```\n\n**Repo:**\n\n-   GitHub repository: `binary_trees`\n-   File: `1-binary_tree_insert_left.c`\n\n Done? Help Check your code Get a sandbox\n\n### 2\\. Insert right\n\nmandatory\n\nWrite a function that inserts a node as the right-child of another node\n\n-   Prototype: `binary_tree_t *binary_tree_insert_right(binary_tree_t *parent, int value);`\n-   Where `parent` is a pointer to the node to insert the right-child in\n-   And `value` is the value to store in the new node\n-   Your function must return a pointer to the created node, or `NULL` on failure or if `parent` is `NULL`\n-   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.\n\n```\nalex@/tmp/binary_trees$ cat 2-main.c\n#include \u003cstdlib.h\u003e\n#include \u003cstdio.h\u003e\n#include \"binary_trees.h\"\n\n/**\n * main - Entry point\n *\n * Return: Always 0 (Success)\n */\nint main(void)\n{\n    binary_tree_t *root;\n\n    root = binary_tree_node(NULL, 98);\n    root-\u003eleft = binary_tree_node(root, 12);\n    root-\u003eright = binary_tree_node(root, 402);\n    binary_tree_print(root);\n    printf(\"\\n\");\n    binary_tree_insert_right(root-\u003eleft, 54);\n    binary_tree_insert_right(root, 128);\n    binary_tree_print(root);\n    return (0);\n}\nalex@/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\nalex@/tmp/binary_trees$ ./2-right\n  .--(098)--.\n(012)     (402)\n\n  .-------(098)--.\n(012)--.       (128)--.\n     (054)          (402)\nalex@/tmp/binary_trees$\n\n```\n\n**Repo:**\n\n-   GitHub repository: `binary_trees`\n-   File: `2-binary_tree_insert_right.c`\n\n Done? Help Check your code Get a sandbox\n\n### 3\\. Delete\n\nmandatory\n\nWrite a function that deletes an entire binary tree\n\n-   Prototype: `void binary_tree_delete(binary_tree_t *tree);`\n-   Where `tree` is a pointer to the root node of the tree to delete\n-   If `tree` is `NULL`, do nothing\n\n```\nalex@/tmp/binary_trees$ cat 3-main.c\n#include \u003cstdlib.h\u003e\n#include \u003cstdio.h\u003e\n#include \"binary_trees.h\"\n\n/**\n * main - Entry point\n *\n * Return: Always 0 (Success)\n */\nint main(void)\n{\n    binary_tree_t *root;\n\n    root = binary_tree_node(NULL, 98);\n    root-\u003eleft = binary_tree_node(root, 12);\n    root-\u003eright = binary_tree_node(root, 402);\n    binary_tree_insert_right(root-\u003eleft, 54);\n    binary_tree_insert_right(root, 128);\n    binary_tree_print(root);\n    binary_tree_delete(root);\n    return (0);\n}\nalex@/tmp/binary_trees$ gcc -Wall -Wextra -Werror -pedantic binary_tree_print.c 3-main.c 3-binary_tree_delete.c 0-binary_tree_node.c 2-binary_tree_insert_right.c -o 3-del\nalex@/tmp/binary_trees$ valgrind ./3-del\n==13264== Memcheck, a memory error detector\n==13264== Copyright (C) 2002-2013, and GNU GPL'd, by Julian Seward et al.\n==13264== Using Valgrind-3.10.1 and LibVEX; rerun with -h for copyright info\n==13264== Command: ./3-del\n==13264==\n  .-------(098)--.\n(012)--.       (128)--.\n     (054)          (402)\n==13264==\n==13264== HEAP SUMMARY:\n==13264==     in use at exit: 0 bytes in 0 blocks\n==13264==   total heap usage: 9 allocs, 9 frees, 949 bytes allocated\n==13264==\n==13264== All heap blocks were freed -- no leaks are possible\n==13264==\n==13264== For counts of detected and suppressed errors, rerun with: -v\n==13264== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)\nalex@/tmp/binary_trees$\n\n```\n\n**Repo:**\n\n-   GitHub repository: `binary_trees`\n-   File: `3-binary_tree_delete.c`\n\n Done? Help Check your code Get a sandbox\n\n### 4\\. Is leaf\n\nmandatory\n\nWrite a function that checks if a node is a leaf\n\n-   Prototype: `int binary_tree_is_leaf(const binary_tree_t *node);`\n-   Where `node` is a pointer to the node to check\n-   Your function must return `1` if `node` is a leaf, otherwise `0`\n-   If `node` is `NULL`, return `0`\n\n```\nalex@/tmp/binary_trees$ cat 4-main.c\n#include \u003cstdlib.h\u003e\n#include \u003cstdio.h\u003e\n#include \"binary_trees.h\"\n\n/**\n * main - Entry point\n *\n * Return: Always 0 (Success)\n */\nint main(void)\n{\n    binary_tree_t *root;\n    int ret;\n\n    root = binary_tree_node(NULL, 98);\n    root-\u003eleft = binary_tree_node(root, 12);\n    root-\u003eright = binary_tree_node(root, 402);\n    binary_tree_insert_right(root-\u003eleft, 54);\n    binary_tree_insert_right(root, 128);\n    binary_tree_print(root);\n\n    ret = binary_tree_is_leaf(root);\n    printf(\"Is %d a leaf: %d\\n\", root-\u003en, ret);\n    ret = binary_tree_is_leaf(root-\u003eright);\n    printf(\"Is %d a leaf: %d\\n\", root-\u003eright-\u003en, ret);\n    ret = binary_tree_is_leaf(root-\u003eright-\u003eright);\n    printf(\"Is %d a leaf: %d\\n\", root-\u003eright-\u003eright-\u003en, ret);\n    return (0);\n}\nalex@/tmp/binary_trees$ gcc -Wall -Wextra -Werror -pedantic binary_tree_print.c 4-binary_tree_is_leaf.c 4-main.c 0-binary_tree_node.c 2-binary_tree_insert_right.c -o 4-leaf\nalex@/tmp/binary_trees$ ./4-leaf\n  .-------(098)--.\n(012)--.       (128)--.\n     (054)          (402)\nIs 98 a leaf: 0\nIs 128 a leaf: 0\nIs 402 a leaf: 1\nalex@/tmp/binary_trees$\n\n```\n\n**Repo:**\n\n-   GitHub repository: `binary_trees`\n-   File: `4-binary_tree_is_leaf.c`\n\n Done? Help Check your code Get a sandbox\n\n### 5\\. Is root\n\nmandatory\n\nWrite a function that checks if a given node is a root\n\n-   Prototype: `int binary_tree_is_root(const binary_tree_t *node);`\n-   Where `node` is a pointer to the node to check\n-   Your function must return `1` if `node` is a root, otherwise `0`\n-   If `node` is `NULL`, return `0`\n\n```\nalex@/tmp/binary_trees$ cat 5-main.c\n#include \u003cstdlib.h\u003e\n#include \u003cstdio.h\u003e\n#include \"binary_trees.h\"\n\n/**\n * main - Entry point\n *\n * Return: Always 0 (Success)\n */\nint main(void)\n{\n    binary_tree_t *root;\n    int ret;\n\n    root = binary_tree_node(NULL, 98);\n    root-\u003eleft = binary_tree_node(root, 12);\n    root-\u003eright = binary_tree_node(root, 402);\n    binary_tree_insert_right(root-\u003eleft, 54);\n    binary_tree_insert_right(root, 128);\n    binary_tree_print(root);\n\n    ret = binary_tree_is_root(root);\n    printf(\"Is %d a root: %d\\n\", root-\u003en, ret);\n    ret = binary_tree_is_root(root-\u003eright);\n    printf(\"Is %d a root: %d\\n\", root-\u003eright-\u003en, ret);\n    ret = binary_tree_is_root(root-\u003eright-\u003eright);\n    printf(\"Is %d a root: %d\\n\", root-\u003eright-\u003eright-\u003en, ret);\n    return (0);\n}\nalex@/tmp/binary_trees$ gcc -Wall -Wextra -Werror -pedantic binary_tree_print.c 5-binary_tree_is_root.c 5-main.c 0-binary_tree_node.c 2-binary_tree_insert_right.c -o 5-root\nalex@/tmp/binary_trees$ ./5-root\n  .-------(098)--.\n(012)--.       (128)--.\n     (054)          (402)\nIs 98 a root: 1\nIs 128 a root: 0\nIs 402 a root: 0\nalex@/tmp/binary_trees$\n\n```\n\n**Repo:**\n\n-   GitHub repository: `binary_trees`\n-   File: `5-binary_tree_is_root.c`\n\n Done? Help Check your code Get a sandbox\n\n### 6\\. Pre-order traversal\n\nmandatory\n\nWrite a function that goes through a binary tree using pre-order traversal\n\n-   Prototype: `void binary_tree_preorder(const binary_tree_t *tree, void (*func)(int));`\n-   Where `tree` is a pointer to the root node of the tree to traverse\n-   And `func` is a pointer to a function to call for each node. The value in the node must be passed as a parameter to this function.\n-   If `tree` or `func` is `NULL`, do nothing\n\n```\nalex@/tmp/binary_trees$ cat 6-main.c\n#include \u003cstdlib.h\u003e\n#include \u003cstdio.h\u003e\n#include \"binary_trees.h\"\n\n/**\n * print_num - Prints a number\n *\n * @n: Number to be printed\n */\nvoid print_num(int n)\n{\n    printf(\"%d\\n\", n);\n}\n\n/**\n * main - Entry point\n *\n * Return: Always 0 (Success)\n */\nint main(void)\n{\n    binary_tree_t *root;\n\n    root = binary_tree_node(NULL, 98);\n    root-\u003eleft = binary_tree_node(root, 12);\n    root-\u003eright = binary_tree_node(root, 402);\n    root-\u003eleft-\u003eleft = binary_tree_node(root-\u003eleft, 6);\n    root-\u003eleft-\u003eright = binary_tree_node(root-\u003eleft, 56);\n    root-\u003eright-\u003eleft = binary_tree_node(root-\u003eright, 256);\n    root-\u003eright-\u003eright = binary_tree_node(root-\u003eright, 512);\n\n    binary_tree_print(root);\n    binary_tree_preorder(root, \u0026print_num);\n    return (0);\n}\nalex@/tmp/binary_trees$ gcc -Wall -Wextra -Werror -pedantic binary_tree_print.c 6-main.c 6-binary_tree_preorder.c 0-binary_tree_node.c -o 6-pre\nalex@/tmp/binary_trees$ ./6-pre\n       .-------(098)-------.\n  .--(012)--.         .--(402)--.\n(006)     (056)     (256)     (512)\n98\n12\n6\n56\n402\n256\n512\nalex@/tmp/binary_trees$\n\n```\n\n**Repo:**\n\n-   GitHub repository: `binary_trees`\n-   File: `6-binary_tree_preorder.c`\n\n Done? Help Check your code Get a sandbox\n\n### 7\\. In-order traversal\n\nmandatory\n\nWrite a function that goes through a binary tree using in-order traversal\n\n-   Prototype: `void binary_tree_inorder(const binary_tree_t *tree, void (*func)(int));`\n-   Where `tree` is a pointer to the root node of the tree to traverse\n-   And `func` is a pointer to a function to call for each node. The value in the node must be passed as a parameter to this function.\n-   If `tree` or `func` is `NULL`, do nothing\n\n```\nalex@/tmp/binary_trees$ cat 7-main.c\n#include \u003cstdlib.h\u003e\n#include \u003cstdio.h\u003e\n#include \"binary_trees.h\"\n\n/**\n * print_num - Prints a number\n *\n * @n: Number to be printed\n */\nvoid print_num(int n)\n{\n    printf(\"%d\\n\", n);\n}\n\n/**\n * main - Entry point\n *\n * Return: Always 0 (Success)\n */\nint main(void)\n{\n    binary_tree_t *root;\n\n    root = binary_tree_node(NULL, 98);\n    root-\u003eleft = binary_tree_node(root, 12);\n    root-\u003eright = binary_tree_node(root, 402);\n    root-\u003eleft-\u003eleft = binary_tree_node(root-\u003eleft, 6);\n    root-\u003eleft-\u003eright = binary_tree_node(root-\u003eleft, 56);\n    root-\u003eright-\u003eleft = binary_tree_node(root-\u003eright, 256);\n    root-\u003eright-\u003eright = binary_tree_node(root-\u003eright, 512);\n\n    binary_tree_print(root);\n    binary_tree_inorder(root, \u0026print_num);\n    return (0);\n}\nalex@/tmp/binary_trees$ gcc -Wall -Wextra -Werror -pedantic binary_tree_print.c 7-main.c 7-binary_tree_inorder.c 0-binary_tree_node.c -o 7-in\nalex@/tmp/binary_trees$ ./7-in\n       .-------(098)-------.\n  .--(012)--.         .--(402)--.\n(006)     (056)     (256)     (512)\n6\n12\n56\n98\n256\n402\n512\nalex@/tmp/binary_trees$\n\n```\n\n**Repo:**\n\n-   GitHub repository: `binary_trees`\n-   File: `7-binary_tree_inorder.c`\n\n Done? Help Check your code Get a sandbox\n\n### 8\\. Post-order traversal\n\nmandatory\n\nWrite a function that goes through a binary tree using post-order traversal\n\n-   Prototype: `void binary_tree_postorder(const binary_tree_t *tree, void (*func)(int));`\n-   Where `tree` is a pointer to the root node of the tree to traverse\n-   And `func` is a pointer to a function to call for each node. The value in the node must be passed as a parameter to this function.\n-   If `tree` or `func` is `NULL`, do nothing\n\n```\nalex@/tmp/binary_trees$ cat 8-main.c\n#include \u003cstdlib.h\u003e\n#include \u003cstdio.h\u003e\n#include \"binary_trees.h\"\n\n/**\n * print_num - Prints a number\n *\n * @n: Number to be printed\n */\nvoid print_num(int n)\n{\n    printf(\"%d\\n\", n);\n}\n\n/**\n * main - Entry point\n *\n * Return: Always 0 (Success)\n */\nint main(void)\n{\n    binary_tree_t *root;\n\n    root = binary_tree_node(NULL, 98);\n    root-\u003eleft = binary_tree_node(root, 12);\n    root-\u003eright = binary_tree_node(root, 402);\n    root-\u003eleft-\u003eleft = binary_tree_node(root-\u003eleft, 6);\n    root-\u003eleft-\u003eright = binary_tree_node(root-\u003eleft, 56);\n    root-\u003eright-\u003eleft = binary_tree_node(root-\u003eright, 256);\n    root-\u003eright-\u003eright = binary_tree_node(root-\u003eright, 512);\n\n    binary_tree_print(root);\n    binary_tree_postorder(root, \u0026print_num);\n    return (0);\n}\nalex@/tmp/binary_trees$ gcc -Wall -Wextra -Werror -pedantic binary_tree_print.c 8-main.c 8-binary_tree_postorder.c 0-binary_tree_node.c -o 8-post\nalex@/tmp/binary_trees$ ./8-post\n       .-------(098)-------.\n  .--(012)--.         .--(402)--.\n(006)     (056)     (256)     (512)\n6\n56\n12\n256\n512\n402\n98\nalex@/tmp/binary_trees$\n\n```\n\n**Repo:**\n\n-   GitHub repository: `binary_trees`\n-   File: `8-binary_tree_postorder.c`\n\n Done? Help Check your code Get a sandbox\n\n### 9\\. Height\n\nmandatory\n\nWrite a function that measures the height of a binary tree\n\n-   Prototype: `size_t binary_tree_height(const binary_tree_t *tree);`\n-   Where `tree` is a pointer to the root node of the tree to measure the height.\n-   If `tree` is `NULL`, your function must return `0`\n\n```\nalex@/tmp/binary_trees$ cat 9-main.c\n#include \u003cstdlib.h\u003e\n#include \u003cstdio.h\u003e\n#include \"binary_trees.h\"\n\n/**\n * main - Entry point\n *\n * Return: Always 0 (Success)\n */\nint main(void)\n{\n    binary_tree_t *root;\n    size_t height;\n\n    root = binary_tree_node(NULL, 98);\n    root-\u003eleft = binary_tree_node(root, 12);\n    root-\u003eright = binary_tree_node(root, 402);\n    binary_tree_insert_right(root-\u003eleft, 54);\n    binary_tree_insert_right(root, 128);\n    binary_tree_print(root);\n\n    height = binary_tree_height(root);\n    printf(\"Height from %d: %lu\\n\", root-\u003en, height);\n    height = binary_tree_height(root-\u003eright);\n    printf(\"Height from %d: %lu\\n\", root-\u003eright-\u003en, height);\n    height = binary_tree_height(root-\u003eleft-\u003eright);\n    printf(\"Height from %d: %lu\\n\", root-\u003eleft-\u003eright-\u003en, height);\n    return (0);\n}\nalex@/tmp/binary_trees$ gcc -Wall -Wextra -Werror -pedantic binary_tree_print.c 9-binary_tree_height.c 9-main.c 0-binary_tree_node.c 2-binary_tree_insert_right.c -o 9-height\nalex@/tmp/binary_trees$ ./9-height\n  .-------(098)--.\n(012)--.       (128)--.\n     (054)          (402)\nHeight from 98: 2\nHeight from 128: 1\nHeight from 54: 0\nalex@/tmp/binary_trees$\n\n```\n\n**Repo:**\n\n-   GitHub repository: `binary_trees`\n-   File: `9-binary_tree_height.c`\n\n Done? Help Check your code Get a sandbox\n\n### 10\\. Depth\n\nmandatory\n\nWrite a function that measures the depth of a node in a binary tree\n\n-   Prototype: `size_t binary_tree_depth(const binary_tree_t *tree);`\n-   Where `tree` is a pointer to the node to measure the depth\n-   If `tree` is `NULL`, your function must return `0`\n\n```\nalex@/tmp/binary_trees$ cat 10-main.c\n#include \u003cstdlib.h\u003e\n#include \u003cstdio.h\u003e\n#include \"binary_trees.h\"\n\n/**\n * main - Entry point\n *\n * Return: Always 0 (Success)\n */\nint main(void)\n{\n    binary_tree_t *root;\n    size_t depth;\n\n    root = binary_tree_node(NULL, 98);\n    root-\u003eleft = binary_tree_node(root, 12);\n    root-\u003eright = binary_tree_node(root, 402);\n    binary_tree_insert_right(root-\u003eleft, 54);\n    binary_tree_insert_right(root, 128);\n    binary_tree_print(root);\n\n    depth = binary_tree_depth(root);\n    printf(\"Depth of %d: %lu\\n\", root-\u003en, depth);\n    depth = binary_tree_depth(root-\u003eright);\n    printf(\"Depth of %d: %lu\\n\", root-\u003eright-\u003en, depth);\n    depth = binary_tree_depth(root-\u003eleft-\u003eright);\n    printf(\"Depth of %d: %lu\\n\", root-\u003eleft-\u003eright-\u003en, depth);\n    return (0);\n}\nalex@/tmp/binary_trees$ gcc -Wall -Wextra -Werror -pedantic binary_tree_print.c 10-binary_tree_depth.c 10-main.c 0-binary_tree_node.c 2-binary_tree_insert_right.c -o 10-depth\nalex@/tmp/binary_trees$ ./10-depth\n  .-------(098)--.\n(012)--.       (128)--.\n     (054)          (402)\nDepth of 98: 0\nDepth of 128: 1\nDepth of 54: 2\nalex@/tmp/binary_trees$\n\n```\n\n**Repo:**\n\n-   GitHub repository: `binary_trees`\n-   File: `10-binary_tree_depth.c`\n\n Done? Help Check your code Get a sandbox\n\n### 11\\. Size\n\nmandatory\n\nWrite a function that measures the size of a binary tree\n\n-   Prototype: `size_t binary_tree_size(const binary_tree_t *tree);`\n-   Where `tree` is a pointer to the root node of the tree to measure the size\n-   If `tree` is `NULL`, the function must return 0\n\n```\nalex@/tmp/binary_trees$ cat 11-main.c\n#include \u003cstdlib.h\u003e\n#include \u003cstdio.h\u003e\n#include \"binary_trees.h\"\n\n/**\n * main - Entry point\n *\n * Return: Always 0 (Success)\n */\nint main(void)\n{\n    binary_tree_t *root;\n    size_t size;\n\n    root = binary_tree_node(NULL, 98);\n    root-\u003eleft = binary_tree_node(root, 12);\n    root-\u003eright = binary_tree_node(root, 402);\n    binary_tree_insert_right(root-\u003eleft, 54);\n    binary_tree_insert_right(root, 128);\n    binary_tree_print(root);\n\n    size = binary_tree_size(root);\n    printf(\"Size of %d: %lu\\n\", root-\u003en, size);\n    size = binary_tree_size(root-\u003eright);\n    printf(\"Size of %d: %lu\\n\", root-\u003eright-\u003en, size);\n    size = binary_tree_size(root-\u003eleft-\u003eright);\n    printf(\"Size of %d: %lu\\n\", root-\u003eleft-\u003eright-\u003en, size);\n    return (0);\n}\nalex@/tmp/binary_trees$ gcc -Wall -Wextra -Werror -pedantic binary_tree_print.c 11-binary_tree_size.c 11-main.c 0-binary_tree_node.c 2-binary_tree_insert_right.c -o 11-size\nalex@/tmp/binary_trees$ ./11-size\n  .-------(098)--.\n(012)--.       (128)--.\n     (054)          (402)\nSize of 98: 5\nSize of 128: 2\nSize of 54: 1\nalex@/tmp/binary_trees$\n\n```\n\n**Repo:**\n\n-   GitHub repository: `binary_trees`\n-   File: `11-binary_tree_size.c`\n\n Done? Help Check your code Get a sandbox\n\n### 12\\. Leaves\n\nmandatory\n\nWrite a function that counts the leaves in a binary tree\n\n-   Prototype: `size_t binary_tree_leaves(const binary_tree_t *tree);`\n-   Where `tree` is a pointer to the root node of the tree to count the number of leaves\n-   If `tree` is `NULL`, the function must return 0\n-   A `NULL` pointer is not a leaf\n\n```\nalex@/tmp/binary_trees$ cat 12-main.c\n#include \u003cstdlib.h\u003e\n#include \u003cstdio.h\u003e\n#include \"binary_trees.h\"\n\n/**\n * main - Entry point\n *\n * Return: Always 0 (Success)\n */\nint main(void)\n{\n    binary_tree_t *root;\n    size_t leaves;\n\n    root = binary_tree_node(NULL, 98);\n    root-\u003eleft = binary_tree_node(root, 12);\n    root-\u003eright = binary_tree_node(root, 402);\n    binary_tree_insert_right(root-\u003eleft, 54);\n    binary_tree_insert_right(root, 128);\n    binary_tree_print(root);\n\n    leaves = binary_tree_leaves(root);\n    printf(\"Leaves in %d: %lu\\n\", root-\u003en, leaves);\n    leaves = binary_tree_leaves(root-\u003eright);\n    printf(\"Leaves in %d: %lu\\n\", root-\u003eright-\u003en, leaves);\n    leaves = binary_tree_leaves(root-\u003eleft-\u003eright);\n    printf(\"Leaves in %d: %lu\\n\", root-\u003eleft-\u003eright-\u003en, leaves);\n    return (0);\n}\nalex@/tmp/binary_trees$ gcc -Wall -Wextra -Werror -pedantic binary_tree_print.c 12-binary_tree_leaves.c 12-main.c 0-binary_tree_node.c 2-binary_tree_insert_right.c -o 12-leaves\nalex@/tmp/binary_trees$ ./12-leaves\n  .-------(098)--.\n(012)--.       (128)--.\n     (054)          (402)\nLeaves in 98: 2\nLeaves in 128: 1\nLeaves in 54: 1\nalex@/tmp/binary_trees$\n\n```\n\n**Repo:**\n\n-   GitHub repository: `binary_trees`\n-   File: `12-binary_tree_leaves.c`\n\n Done? Help Check your code Get a sandbox\n\n### 13\\. Nodes\n\nmandatory\n\nWrite a function that counts the nodes with at least 1 child in a binary tree\n\n-   Prototype: `size_t binary_tree_nodes(const binary_tree_t *tree);`\n-   Where `tree` is a pointer to the root node of the tree to count the number of nodes\n-   If `tree` is `NULL`, the function must return 0\n-   A `NULL` pointer is not a node\n\n```\nalex@/tmp/binary_trees$ cat 13-main.c\n#include \u003cstdlib.h\u003e\n#include \u003cstdio.h\u003e\n#include \"binary_trees.h\"\n\n/**\n * main - Entry point\n *\n * Return: Always 0 (Success)\n */\nint main(void)\n{\n    binary_tree_t *root;\n    size_t nodes;\n\n    root = binary_tree_node(NULL, 98);\n    root-\u003eleft = binary_tree_node(root, 12);\n    root-\u003eright = binary_tree_node(root, 402);\n    binary_tree_insert_right(root-\u003eleft, 54);\n    binary_tree_insert_right(root, 128);\n    binary_tree_print(root);\n\n    nodes = binary_tree_nodes(root);\n    printf(\"Nodes in %d: %lu\\n\", root-\u003en, nodes);\n    nodes = binary_tree_nodes(root-\u003eright);\n    printf(\"Nodes in %d: %lu\\n\", root-\u003eright-\u003en, nodes);\n    nodes = binary_tree_nodes(root-\u003eleft-\u003eright);\n    printf(\"Nodes in %d: %lu\\n\", root-\u003eleft-\u003eright-\u003en, nodes);\n    return (0);\n}\nalex@/tmp/binary_trees$ gcc -Wall -Wextra -Werror -pedantic binary_tree_print.c 13-binary_tree_nodes.c 13-main.c 0-binary_tree_node.c 2-binary_tree_insert_right.c -o 13-nodes\nalex@/tmp/binary_trees$ ./13-nodes\n  .-------(098)--.\n(012)--.       (128)--.\n     (054)          (402)\nNodes in 98: 3\nNodes in 128: 1\nNodes in 54: 0\nalex@/tmp/binary_trees$\n\n```\n\n**Repo:**\n\n-   GitHub repository: `binary_trees`\n-   File: `13-binary_tree_nodes.c`\n\n Done? Help Check your code Get a sandbox\n\n### 14\\. Balance factor\n\nmandatory\n\nWrite a function that measures the balance factor of a binary tree\n\n-   Prototype: `int binary_tree_balance(const binary_tree_t *tree);`\n-   Where `tree` is a pointer to the root node of the tree to measure the balance factor\n-   If `tree` is `NULL`, return `0`\n\n```\nalex@/tmp/binary_trees$ cat 14-main.c\n#include \u003cstdlib.h\u003e\n#include \u003cstdio.h\u003e\n#include \"binary_trees.h\"\n\n/**\n * main - Entry point\n *\n * Return: Always 0 (Success)\n */\nint main(void)\n{\n    binary_tree_t *root;\n    int balance;\n\n    root = binary_tree_node(NULL, 98);\n    root-\u003eleft = binary_tree_node(root, 12);\n    root-\u003eright = binary_tree_node(root, 402);\n    binary_tree_insert_right(root-\u003eleft, 54);\n    binary_tree_insert_right(root, 128);\n    binary_tree_insert_left(root, 45);\n    binary_tree_insert_right(root-\u003eleft, 50);\n    binary_tree_insert_left(root-\u003eleft-\u003eleft, 10);\n    binary_tree_insert_left(root-\u003eleft-\u003eleft-\u003eleft, 8);\n    binary_tree_print(root);\n\n    balance = binary_tree_balance(root);\n    printf(\"Balance of %d: %+d\\n\", root-\u003en, balance);\n    balance = binary_tree_balance(root-\u003eright);\n    printf(\"Balance of %d: %+d\\n\", root-\u003eright-\u003en, balance);\n    balance = binary_tree_balance(root-\u003eleft-\u003eleft-\u003eright);\n    printf(\"Balance of %d: %+d\\n\", root-\u003eleft-\u003eleft-\u003eright-\u003en, balance);\n    return (0);\n}\nalex@/tmp/binary_trees$ gcc -Wall -Wextra -Werror -pedantic binary_tree_print.c 14-binary_tree_balance.c 14-main.c 0-binary_tree_node.c 2-binary_tree_insert_right.c 1-binary_tree_insert_left.c -o 14-balance\nalex@/tmp/binary_trees$ ./14-balance\n                      .-------(098)--.\n            .-------(045)--.       (128)--.\n       .--(012)--.       (050)          (402)\n  .--(010)     (054)\n(008)\nBalance of 98: +2\nBalance of 128: -1\nBalance of 54: +0\nalex@/tmp/binary_trees$\n\n```\n\n**Repo:**\n\n-   GitHub repository: `binary_trees`\n-   File: `14-binary_tree_balance.c`\n\n Done? Help Check your code Get a sandbox\n\n### 15\\. Is full\n\nmandatory\n\nWrite a function that checks if a binary tree is full\n\n-   Prototype: `int binary_tree_is_full(const binary_tree_t *tree);`\n-   Where `tree` is a pointer to the root node of the tree to check\n-   If `tree` is `NULL`, your function must return `0`\n\n```\nalex@/tmp/binary_trees$ cat 15-main.c\n#include \u003cstdlib.h\u003e\n#include \u003cstdio.h\u003e\n#include \"binary_trees.h\"\n\n/**\n * main - Entry point\n *\n * Return: Always 0 (Success)\n */\nint main(void)\n{\n    binary_tree_t *root;\n    int full;\n\n    root = binary_tree_node(NULL, 98);\n    root-\u003eleft = binary_tree_node(root, 12);\n    root-\u003eright = binary_tree_node(root, 402);\n    binary_tree_insert_right(root-\u003eleft, 54);\n    binary_tree_insert_right(root, 128);\n    root-\u003eleft-\u003eleft = binary_tree_node(root-\u003eleft, 10);\n    binary_tree_print(root);\n\n    full = binary_tree_is_full(root);\n    printf(\"Is %d full: %d\\n\", root-\u003en, full);\n    full = binary_tree_is_full(root-\u003eleft);\n    printf(\"Is %d full: %d\\n\", root-\u003eleft-\u003en, full);\n    full = binary_tree_is_full(root-\u003eright);\n    printf(\"Is %d full: %d\\n\", root-\u003eright-\u003en, full);\n    return (0);\n}\nalex@/tmp/binary_trees$ gcc -Wall -Wextra -Werror -pedantic binary_tree_print.c 15-binary_tree_is_full.c 15-main.c 0-binary_tree_node.c 2-binary_tree_insert_right.c -o 15-full\nalex@/tmp/binary_trees$ ./15-full\n       .-------(098)--.\n  .--(012)--.       (128)--.\n(010)     (054)          (402)\nIs 98 full: 0\nIs 12 full: 1\nIs 128 full: 0\nalex@/tmp/binary_trees$\n\n```\n\n**Repo:**\n\n-   GitHub repository: `binary_trees`\n-   File: `15-binary_tree_is_full.c`\n\n Done? Help Check your code Get a sandbox\n\n### 16\\. Is perfect\n\nmandatory\n\nWrite a function that checks if a binary tree is perfect\n\n-   Prototype: `int binary_tree_is_perfect(const binary_tree_t *tree);`\n-   Where `tree` is a pointer to the root node of the tree to check\n-   If `tree` is `NULL`, your function must return `0`\n\n```\nalex@/tmp/binary_trees$ cat 16-main.c\n#include \u003cstdlib.h\u003e\n#include \u003cstdio.h\u003e\n#include \"binary_trees.h\"\n\n/**\n * main - Entry point\n *\n * Return: Always 0 (Success)\n */\nint main(void)\n{\n    binary_tree_t *root;\n    int perfect;\n\n    root = binary_tree_node(NULL, 98);\n    root-\u003eleft = binary_tree_node(root, 12);\n    root-\u003eright = binary_tree_node(root, 402);\n    binary_tree_insert_right(root-\u003eleft, 54);\n    binary_tree_insert_right(root, 128);\n    root-\u003eleft-\u003eleft = binary_tree_node(root-\u003eleft, 10);\n    root-\u003eright-\u003eleft = binary_tree_node(root-\u003eright, 10);\n\n    binary_tree_print(root);\n    perfect = binary_tree_is_perfect(root);\n    printf(\"Perfect: %d\\n\\n\", perfect);\n\n    root-\u003eright-\u003eright-\u003eleft = binary_tree_node(root-\u003eright-\u003eright, 10);\n    binary_tree_print(root);\n    perfect = binary_tree_is_perfect(root);\n    printf(\"Perfect: %d\\n\\n\", perfect);\n\n    root-\u003eright-\u003eright-\u003eright = binary_tree_node(root-\u003eright-\u003eright, 10);\n    binary_tree_print(root);\n    perfect = binary_tree_is_perfect(root);\n    printf(\"Perfect: %d\\n\", perfect);\n    return (0);\n}\nalex@/tmp/binary_trees$ gcc -Wall -Wextra -Werror -pedantic binary_tree_print.c 16-binary_tree_is_perfect.c 16-main.c 0-binary_tree_node.c 2-binary_tree_insert_right.c -o 16-perfect\nalex@/tmp/binary_trees$ ./16-perfect\n       .-------(098)-------.\n  .--(012)--.         .--(128)--.\n(010)     (054)     (010)     (402)\nPerfect: 1\n\n       .-------(098)-------.\n  .--(012)--.         .--(128)-------.\n(010)     (054)     (010)       .--(402)\n                              (010)\nPerfect: 0\n\n       .-------(098)-------.\n  .--(012)--.         .--(128)-------.\n(010)     (054)     (010)       .--(402)--.\n                              (010)     (010)\nPerfect: 0\nalex@/tmp/binary_trees$\n\n```\n\n**Repo:**\n\n-   GitHub repository: `binary_trees`\n-   File: `16-binary_tree_is_perfect.c`\n\n Done? Help Check your code Get a sandbox\n\n### 17\\. Sibling\n\nmandatory\n\nWrite a function that finds the sibling of a node\n\n-   Prototype: `binary_tree_t *binary_tree_sibling(binary_tree_t *node);`\n-   Where `node` is a pointer to the node to find the sibling\n-   Your function must return a pointer to the sibling node\n-   If `node` is `NULL` or the parent is `NULL`, return `NULL`\n-   If `node` has no sibling, return `NULL`\n\n```\nalex@/tmp/binary_trees$ cat 17-main.c\n#include \u003cstdlib.h\u003e\n#include \u003cstdio.h\u003e\n#include \"binary_trees.h\"\n\n/**\n * main - Entry point\n *\n * Return: Always 0 (Success)\n */\nint main(void)\n{\n    binary_tree_t *root;\n    binary_tree_t *sibling;\n\n    root = binary_tree_node(NULL, 98);\n    root-\u003eleft = binary_tree_node(root, 12);\n    root-\u003eright = binary_tree_node(root, 128);\n    root-\u003eleft-\u003eright = binary_tree_node(root-\u003eleft, 54);\n    root-\u003eright-\u003eright = binary_tree_node(root-\u003eright, 402);\n    root-\u003eleft-\u003eleft = binary_tree_node(root-\u003eleft, 10);\n    root-\u003eright-\u003eleft = binary_tree_node(root-\u003eright, 110);\n    root-\u003eright-\u003eright-\u003eleft = binary_tree_node(root-\u003eright-\u003eright, 200);\n    root-\u003eright-\u003eright-\u003eright = binary_tree_node(root-\u003eright-\u003eright, 512);\n\n    binary_tree_print(root);\n    sibling = binary_tree_sibling(root-\u003eleft);\n    printf(\"Sibling of %d: %d\\n\", root-\u003eleft-\u003en, sibling-\u003en);\n    sibling = binary_tree_sibling(root-\u003eright-\u003eleft);\n    printf(\"Sibling of %d: %d\\n\", root-\u003eright-\u003eleft-\u003en, sibling-\u003en);\n    sibling = binary_tree_sibling(root-\u003eleft-\u003eright);\n    printf(\"Sibling of %d: %d\\n\", root-\u003eleft-\u003eright-\u003en, sibling-\u003en);\n    sibling = binary_tree_sibling(root);\n    printf(\"Sibling of %d: %p\\n\", root-\u003en, (void *)sibling);\n    return (0);\n}\nalex@/tmp/binary_trees$ gcc -Wall -Wextra -Werror -pedantic binary_tree_print.c 17-main.c 17-binary_tree_sibling.c 0-binary_tree_node.c -o 17-sibling\nalex@/tmp/binary_trees$ ./17-sibling\n       .-------(098)-------.\n  .--(012)--.         .--(128)-------.\n(010)     (054)     (110)       .--(402)--.\n                              (200)     (512)\nSibling of 12: 128\nSibling of 110: 402\nSibling of 54: 10\nSibling of 98: (nil)\nalex@/tmp/binary_trees$\n\n```\n\n**Repo:**\n\n-   GitHub repository: `binary_trees`\n-   File: `17-binary_tree_sibling.c`\n\n Done? Help Check your code Get a sandbox\n\n### 18\\. Uncle\n\nmandatory\n\nWrite a function that finds the uncle of a node\n\n-   Prototype: `binary_tree_t *binary_tree_uncle(binary_tree_t *node);`\n-   Where `node` is a pointer to the node to find the uncle\n-   Your function must return a pointer to the uncle node\n-   If `node` is `NULL`, return `NULL`\n-   If `node` has no uncle, return `NULL`\n\n```\nalex@/tmp/binary_trees$ cat 18-main.c\n#include \u003cstdlib.h\u003e\n#include \u003cstdio.h\u003e\n#include \"binary_trees.h\"\n\n/**\n * main - Entry point\n *\n * Return: Always 0 (Success)\n */\nint main(void)\n{\n    binary_tree_t *root;\n    binary_tree_t *uncle;\n\n    root = binary_tree_node(NULL, 98);\n    root-\u003eleft = binary_tree_node(root, 12);\n    root-\u003eright = binary_tree_node(root, 128);\n    root-\u003eleft-\u003eright = binary_tree_node(root-\u003eleft, 54);\n    root-\u003eright-\u003eright = binary_tree_node(root-\u003eright, 402);\n    root-\u003eleft-\u003eleft = binary_tree_node(root-\u003eleft, 10);\n    root-\u003eright-\u003eleft = binary_tree_node(root-\u003eright, 110);\n    root-\u003eright-\u003eright-\u003eleft = binary_tree_node(root-\u003eright-\u003eright, 200);\n    root-\u003eright-\u003eright-\u003eright = binary_tree_node(root-\u003eright-\u003eright, 512);\n\n    binary_tree_print(root);\n    uncle = binary_tree_uncle(root-\u003eright-\u003eleft);\n    printf(\"Uncle of %d: %d\\n\", root-\u003eright-\u003eleft-\u003en, uncle-\u003en);\n    uncle = binary_tree_uncle(root-\u003eleft-\u003eright);\n    printf(\"Uncle of %d: %d\\n\", root-\u003eleft-\u003eright-\u003en, uncle-\u003en);\n    uncle = binary_tree_uncle(root-\u003eleft);\n    printf(\"Uncle of %d: %p\\n\", root-\u003eleft-\u003en, (void *)uncle);\n    return (0);\n}\nalex@/tmp/binary_trees$ gcc -Wall -Wextra -Werror -pedantic binary_tree_print.c 18-main.c 18-binary_tree_uncle.c 0-binary_tree_node.c -o 18-uncle\nalex@/tmp/binary_trees$ ./18-uncle\n       .-------(098)-------.\n  .--(012)--.         .--(128)-------.\n(010)     (054)     (110)       .--(402)--.\n                              (200)     (512)\nUncle of 110: 12\nUncle of 54: 128\nUncle of 12: (nil)\nalex@/tmp/binary_trees$\n\n```\n\n**Repo:**\n\n-   GitHub repository: `binary_trees`\n-   File: `18-binary_tree_uncle.c`\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpericles001%2Fbinary_trees","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpericles001%2Fbinary_trees","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpericles001%2Fbinary_trees/lists"}