{"id":18792366,"url":"https://github.com/kplanisphere/binary-tree-operations","last_synced_at":"2025-07-17T09:34:21.291Z","repository":{"id":241973145,"uuid":"808350223","full_name":"KPlanisphere/binary-tree-operations","owner":"KPlanisphere","description":"Proyecto 8 - Estructuras de Datos","archived":false,"fork":false,"pushed_at":"2024-05-30T22:18:53.000Z","size":5,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-12-29T15:26:05.479Z","etag":null,"topics":["binary-tree","cpp","data-structures","in-order","node-insertion","post-order","pre-order","tree-operations","tree-traversal"],"latest_commit_sha":null,"homepage":"https://linktr.ee/planisphere.kgz","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/KPlanisphere.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}},"created_at":"2024-05-30T22:18:26.000Z","updated_at":"2024-05-30T22:19:39.000Z","dependencies_parsed_at":null,"dependency_job_id":"4c2c2a26-fcc3-4e06-b9e4-867fde93f2ac","html_url":"https://github.com/KPlanisphere/binary-tree-operations","commit_stats":null,"previous_names":["kplanisphere/binary-tree-operations"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KPlanisphere%2Fbinary-tree-operations","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KPlanisphere%2Fbinary-tree-operations/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KPlanisphere%2Fbinary-tree-operations/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KPlanisphere%2Fbinary-tree-operations/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/KPlanisphere","download_url":"https://codeload.github.com/KPlanisphere/binary-tree-operations/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239718371,"owners_count":19685725,"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","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-tree","cpp","data-structures","in-order","node-insertion","post-order","pre-order","tree-operations","tree-traversal"],"created_at":"2024-11-07T21:19:38.459Z","updated_at":"2025-02-19T19:14:15.918Z","avatar_url":"https://github.com/KPlanisphere.png","language":"C++","readme":"# Binary Tree Operations\n\nThis project implements a binary tree in C++ with various operations to insert nodes and traverse the tree. The program includes functions to create nodes, insert nodes, and perform different tree traversals such as pre-order, in-order, and post-order. It also features a function to visually display the tree structure.\n\n## Features\n\n- **Insert Node**: Adds a new node to the binary tree.\n- **Pre-order Traversal**: Traverses the tree in pre-order (root, left, right).\n- **In-order Traversal**: Traverses the tree in in-order (left, root, right).\n- **Post-order Traversal**: Traverses the tree in post-order (left, right, root).\n- **Display Tree**: Visually displays the structure of the binary tree.\n- **Menu Interface**: Provides a user-friendly interface to perform the above operations.\n\n## Usage\n\nCompile the program using a C++ compiler and run the executable. You will be prompted to enter the number of nodes and their values, after which you can perform various tree operations.\n\n### Example Commands\n\n1. **Insert Node**: Prompts the user to enter the value for each new node.\n2. **Pre-order Traversal**: Displays the nodes in pre-order traversal.\n3. **In-order Traversal**: Displays the nodes in in-order traversal.\n4. **Post-order Traversal**: Displays the nodes in post-order traversal.\n5. **Display Tree**: Visually displays the tree structure.\n\n## Code Snippets\n\n### Create Node\n\nThis function creates a new node with a given value and initializes its left and right children to NULL.\n\n```cpp\nNDO crearNodo(int x) {\n    NDO nuevoNodo = new(struct nodo); // Create space for the new node\n    nuevoNodo-\u003edato = x; // Assign the value to the new node\n    nuevoNodo-\u003eizq = NULL;\n    nuevoNodo-\u003eder = NULL;\n    return nuevoNodo; // Return the new node\n}\n```\n\n### Insert Node\n\nThis function inserts a new node into the binary tree. If the tree is empty, it creates a new node as the root. Otherwise, it inserts the node in the correct position based on its value.\n\n```cpp\nvoid insertar(NDO\u0026 arbol, int x) {\n    if (arbol == NULL) { // Check if the tree is empty\n        arbol = crearNodo(x); // Create a new node\n    } else if (x \u003c arbol-\u003edato) { // If the value is less than the root\n        insertar(arbol-\u003eizq, x); // Insert in the left subtree\n    } else if (x \u003e arbol-\u003edato) { // If the value is greater than the root\n        insertar(arbol-\u003eder, x); // Insert in the right subtree\n    }\n}\n```\n\n### Pre-order Traversal\n\nThis function performs a pre-order traversal of the binary tree, printing the value of each node as it visits them.\n\n```cpp\nvoid preOrden(NDO arbol) {\n    if (arbol != NULL) { // If the node is not NULL\n        cout \u003c\u003c arbol-\u003edato \u003c\u003c \"  \"; // Print the current node\n        preOrden(arbol-\u003eizq); // Recursively traverse the left subtree\n        preOrden(arbol-\u003eder); // Recursively traverse the right subtree\n    }\n}\n```\n\n### Menu Interface\n\nThis part of the code provides a simple interface to interact with the binary tree. It prompts the user to enter the number of nodes and their values, and then displays the tree and performs various traversals.\n\n```cpp\nint main() {\n    NDO arbol = NULL; // Create the binary tree\n\n    int n; // Number of nodes in the tree\n    int x; // Value to insert in each node\n\n    cout \u003c\u003c \"\\n\\t - - - - - GRAFUNGO BINARIO - - - - - \\n\\n\";\n    cout \u003c\u003c \" NUMERO DE NODOS: \";\n    cin \u003e\u003e n;\n    cout \u003c\u003c endl;\n\n    // Insert nodes into the tree\n    cout \u003c\u003c \"\\t NODO \" \u003c\u003c \"| VAL \" \u003c\u003c endl;\n    for (int i = 0; i \u003c n; i++) {\n        cout \u003c\u003c \"\\t  #\" \u003c\u003c i + 1 \u003c\u003c \"  | \"; // Indicator of the current node\n        cin \u003e\u003e x; // Input value\n        insertar(arbol, x);\n    }\n\n    // Display the tree\n    cout \u003c\u003c \"\\n ARBOL GENERADO \\n\\n\";\n    verArbol(arbol, 0);\n\n    // Pre-order traversal\n    cout \u003c\u003c \"\\n\\n PreOrden: \";\n    preOrden(arbol);\n    cout \u003c\u003c endl \u003c\u003c endl;\n\n    // In-order traversal\n    cout \u003c\u003c \"\\n\\n enOrden: \";\n    enOrden(arbol);\n    cout \u003c\u003c endl \u003c\u003c endl;\n\n    // Post-order traversal\n    cout \u003c\u003c \"\\n\\n postOrden: \";\n    postOrden(arbol);\n    cout \u003c\u003c endl \u003c\u003c endl;\n\n    system(\"pause\");\n    return 0;\n}\n```\n## How to Run\n\n1. Clone the repository:\n    ```bash\n    git clone https://github.com/KPlanisphere/binary-tree-operations.git\n    ```\n2. Navigate to the project directory:\n    ```bash\n    cd binary-tree-operations\n    ```\n3. Compile the code:\n    ```bash\n    g++ ABinario_V2.cpp -o binary_tree\n    ```\n4. Run the executable:\n    ```bash\n    ./binary_tree\n    ```\n\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkplanisphere%2Fbinary-tree-operations","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkplanisphere%2Fbinary-tree-operations","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkplanisphere%2Fbinary-tree-operations/lists"}