Algorithms_in_C++  1.0.0
Set of algorithms implemented in C++.
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
argccommandline argument count (ignored)
argvcommandline array of arguments (ignored)
Returns
0 on exit
1298  {
1299  if (argc < 2) {
1300  test1(); // execute 1st test
1301  } else {
1302  test2(std::stoi(argv[1])); // execute 2nd test
1303  }
1304 
1305  return 0;
1306 }
T stoi(T... args)
static void test1()
simple test to insert a given array and delete some item, and print the tree
Definition: tree_234.cpp:1263
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
nupper bound of the range number to insert
1281  {
1283 
1284  for (int64_t i = 0; i < n; i++) {
1285  tree.Insert(i);
1286  }
1287 
1288  tree.Traverse();
1289  tree.Print((std::to_string(n) + ".dot").c_str());
1290 }
2-3-4 tree class
Definition: tree_234.cpp:323
void Print(const char *file_name=nullptr)
Print tree into a dot file.
Definition: tree_234.cpp:1131
void Insert(int64_t item)
Insert item to tree.
Definition: tree_234.cpp:655
void Traverse()
In-order traverse.
Definition: tree_234.cpp:562
T to_string(T... args)
Here is the call graph for this function: