tree_234.cpp File Reference

A demo 2-3-4 tree implementation. More...

`#include <array>`
`#include <cassert>`
`#include <fstream>`
`#include <iostream>`
`#include <memory>`
`#include <queue>`
`#include <string>`
Include dependency graph for tree_234.cpp:

## Classes

class | data_structures::tree_234::Node
| 2-3-4 tree node class More...
class | data_structures::tree_234::Tree234
| 2-3-4 tree class More...

## Namespaces

| data_structures
| Data Structures algorithms.
| tree_234
| Functions for 2–3–4 tree

## Functions

static void | test1 ()
| simple test to insert a given array and delete some item, and print the tree
static void | test2 (int64_t n)
| simple test to insert continuous number of range [0, n), and print the tree More...
int | main (int argc, char *argv[])
| Main function. More...

## Detailed Description

A demo 2-3-4 tree implementation.

2–3–4 tree is a self-balancing data structure that is an isometry of red–black trees. Though we seldom use them in practice, we study them to understand the theory behind Red-Black tree. Please read following links for more infomation. 2–3–4 tree 2-3-4 Trees: A Visual Introduction We Only implement some basic and complicated operations in this demo. Other operations should be easy to be added.

Author
  liuhuan

## Function Documentation

## main()

int main | ( | int | argc,
|  | char * | argv[]
| ) |  |

Main function.

Parameters

  argc | commandline argument count (ignored)
  argv | commandline array of arguments (ignored)

Returns
  0 on exit

{
if (argc < 2) {
test1(); // execute 1st test
} else {
test2(std::stoi(argv[1])); // execute 2nd test
}
return 0;
}
std::stoi
T stoi(T... args)
test1
static void test1()
simple test to insert a given array and delete some item, and print the tree
Definition: tree_234.cpp:1263
test2
static void test2(int64_t n)
simple test to insert continuous number of range [0, n), and print the tree
Definition: tree_234.cpp:1281
Here is the call graph for this function:

## test2()

static void test2 | ( | int64_t | n | ) |

static

simple test to insert continuous number of range [0, n), and print the tree

Parameters

  n | upper bound of the range number to insert

{
data_structures::tree_234::Tree234 tree;
for (int64_t i = 0; i < n; i++) {
tree.Insert(i);
}
tree.Traverse();
tree.Print((std::to_string(n) + ".dot").c_str());
}
data_structures::tree_234::Tree234
2-3-4 tree class
Definition: tree_234.cpp:323
data_structures::tree_234::Tree234::Print
void Print(const char *file_name=nullptr)
Print tree into a dot file.
Definition: tree_234.cpp:1131
data_structures::tree_234::Tree234::Insert
void Insert(int64_t item)
Insert item to tree.
Definition: tree_234.cpp:655
data_structures::tree_234::Tree234::Traverse
void Traverse()
In-order traverse.
Definition: tree_234.cpp:562
std::to_string
T to_string(T... args)
Here is the call graph for this function: