Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/xorz57/binarysearchtree

Binary Search Tree written in C++14
https://github.com/xorz57/binarysearchtree

binary-search-tree cpp data-structures datastructures

Last synced: about 2 months ago
JSON representation

Binary Search Tree written in C++14

Awesome Lists containing this project

README

        

# BinarySearchTree

[![Build](https://github.com/xorz57/BinarySearchTree/actions/workflows/Build.yml/badge.svg)](https://github.com/xorz57/BinarySearchTree/actions/workflows/Build.yml)
[![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=xorz57_BinarySearchTree&metric=alert_status)](https://sonarcloud.io/summary/new_code?id=xorz57_BinarySearchTree)

## Example

```cpp
#include "BinarySearchTree/BinarySearchTree.hpp"

#include
#include

int main() {
binary_search_tree_t tree;

tree.insert(2, "two");
tree.insert(4, "four");
tree.insert(90, "ninety");
tree.insert(3, "three");
tree.insert(0, "zero");
tree.insert(14, "fourteen");
tree.insert(45, "forty-five");

tree.pre_order_traversal([](auto key, auto &value) {
std::cout << key << " -> " << value << std::endl;
});
std::cout << std::endl;

tree.in_order_traversal([](auto key, auto &value) {
std::cout << key << " -> " << value << std::endl;
});
std::cout << std::endl;

tree.post_order_traversal([](auto key, auto &value) {
std::cout << key << " -> " << value << std::endl;
});
std::cout << std::endl;

return 0;
}
```

## How to Build

#### Linux & macOS

```bash
git clone https://github.com/microsoft/vcpkg.git ~/vcpkg
~/vcpkg/bootstrap-vcpkg.sh

git clone https://github.com/xorz57/BinarySearchTree.git
cd BinarySearchTree
cmake -B build -DCMAKE_BUILD_TYPE=Release -S . -DCMAKE_TOOLCHAIN_FILE=~/vcpkg/scripts/buildsystems/vcpkg.cmake
cmake --build build --config Release
ctest --build-config Release
```

#### Windows

```powershell
git clone https://github.com/microsoft/vcpkg.git C:/vcpkg
C:/vcpkg/bootstrap-vcpkg.bat
C:/vcpkg/vcpkg.exe integrate install

git clone https://github.com/xorz57/BinarySearchTree.git
cd BinarySearchTree
cmake -B build -DCMAKE_BUILD_TYPE=Release -S . -DCMAKE_TOOLCHAIN_FILE=C:/vcpkg/scripts/buildsystems/vcpkg.cmake
cmake --build build --config Release
ctest --build-config Release
```