JoaoESmoreira

Binary Tree Iterator Project

This project aims to implement an iterator for a binary tree in C++. The goal is to provide a simple and efficient way to traverse a binary search tree using iterator semantics, similar to the behavior of standard C++ containers.

Repository: Binary-Tree Repository

License: MIT

Languages Used: C++

Tools and Technologies

  • g++ ≥ 9.0 or clang++ ≥ 10.0
  • C++17 or newer standard

Description

The project defines a BinaryTree data structure and an iterator class that allows traversal of the tree in an in-order sequence. This iterator supports standard C++ operations such as incrementing and dereferencing, enabling usage in range-based loops and STL-like algorithms.

Features

  • Implementation of a templated BinaryTree class.
  • Support for inserting, searching, and removing elements.
  • Custom iterator for in-order traversal.
  • Example usage provided in main.cpp.
  • Auxiliary string functions defined in str.cpp.

How to Compile

Use any modern C++ compiler (C++17 or higher).

g++ -std=c++17 -O2 -Wall -Wextra -pedantic main.cpp -o binary-tree

Example Usage

#include "binarytree.hpp"
#include 

int main() {
    BinaryTree bt;

    bt.insert(8);
    bt.insert(3);
    bt.insert(10);
    bt.insert(1);
    bt.insert(6);

    std::cout << "In-order traversal using iterator: ";
    for (auto it = bt.begin(); it != bt.end(); ++it)
        std::cout << *it << " ";
    std::cout << std::endl;

    return 0;
}

Repository Structure

binarytree.hpp
Binary tree and iterator implementation.
main.cpp
Example demonstrating tree operations and iteration.
str.cpp
Auxiliary string handling utilities.
LICENSE
MIT license file.

Footer

Copyright © 2025 Joao ES Moreira

The contents of this website are licensed under the Creative Commons Attribution-NoDerivatives 4.0 International License (CC-BY-ND 4.0).

The source code of this website is licensed under the MIT license, and available in GitHub repositor. User-submitted contributions to the site are welcome, as long as the contributor agrees to license their submission with the CC-BY-ND 4.0 license.