ivanallen / dsa

数据结构与算法
BSD 2-Clause "Simplified" License
27 stars 11 forks source link

Data Structure & Algorithm (DSA)

Build Status

DSA is a library of basic and advanced data structures, as well as common algorithms. We are committed to providing a complete and concise set of code to implement all modules.

Features

How to build

$ bash ./build.sh
$ cd build && make test

Example

The following is an easy demo showing how to create a binary tree.

#include <iostream>
#include <string_view>
#include "binary_tree.h"

using namespace dsa;
using Tree = BinaryTree<int>;

int main() {
    constexpr std::string_view tree_graph = R"(
                  1        <- right_rotate
                /   \
               2     3
             /   \
            4     5

                  ||

                  2
                /   \
               4     1
                   /   \
                  5     3
    )";

    // We can build a binary tree from list
    Tree tree({1, 2, 3, 4, 5});
    std::cout << tree << std::endl;

    // Rotate at root
    tree.right_rotate(1);

    // Print the tree
    std::cout << tree << std::endl;
    return 0;
}

Contact