230# include <tclap/CmdLine.h>
241using namespace Aleph;
255 while (values.size() < n)
257 int val = 1 +
rand() % (n * 10);
261 values.push_back(val);
296 for (
int val : values)
298 if (tree.
search(val) ==
nullptr)
346 for (
int val : values)
348 if (tree.
search(val) ==
nullptr)
368 cout <<
" Written: " <<
prefix <<
"rb.Tree (with color info)" <<
endl;
395 for (
int val : values)
397 if (tree.
search(val) ==
nullptr)
437 for (
int val : values)
439 if (tree.
search(val) ==
nullptr)
479 for (
int val : values)
481 if (tree.
search(val) ==
nullptr)
493 <<
", Nodes: " << tree.
size() <<
endl;
521 for (
int val : values)
523 if (tree.
search(val) ==
nullptr)
550 "Generate tree structure files for visualization.\n"
551 "Creates .Tree files with preorder traversal for btreepic.",
554 TCLAP::ValueArg<size_t>
nArg(
"n",
"count",
555 "Number of elements",
556 false, 30,
"size_t");
559 TCLAP::ValueArg<unsigned int>
seedArg(
"s",
"seed",
560 "Random seed (0 = use time)",
561 false, 0,
"unsigned int");
566 TCLAP::ValueArg<string>
typeArg(
"t",
"type",
567 "Tree type to generate",
571 TCLAP::ValueArg<string>
prefixArg(
"o",
"output",
572 "Output file prefix",
573 false,
"",
"prefix");
578 size_t n =
nArg.getValue();
579 unsigned int seed =
seedArg.getValue();
580 string type =
typeArg.getValue();
584 seed =
time(
nullptr);
586 cout <<
"=== Tree Structure Generator ===" <<
endl;
587 cout <<
"Elements: " << n <<
", Seed: " << seed <<
endl;
596 if (type ==
"all" || type ==
"avl")
602 if (type ==
"all" || type ==
"rb")
608 if (type ==
"all" || type ==
"splay")
614 if (type ==
"all" || type ==
"treap")
620 if (type ==
"all" || type ==
"rand")
626 if (type ==
"all" || type ==
"bin")
628 cout <<
"Binary Tree (unbalanced):" <<
endl;
634 catch (TCLAP::ArgException& e)
636 cerr <<
"Error: " << e.error() <<
" for arg " << e.argId() <<
endl;
Core header for the Aleph-w library.
WeightedDigraph::Node Node
T & insert(const T &item)
Insert a new item by copy.
Node *& getRoot() noexcept
Return the root of tree.
Node * insert(Node *p) noexcept
Insert a node in the tree.
Node * search(const Key &key) const noexcept
Search a key.
Node * search(const Key &key) const noexcept
Search a node containing key; if found, then a pointer to the node containing it is returned; otherwi...
constexpr Node *& getRoot() noexcept
Return a modifiable reference to tree's root.
Node * insert(Node *p) noexcept
Insert the node pointed by p in the tree.
Node * insert(Node *p) noexcept
Insert a node in the tree.
size_t size() const noexcept
Return the number of nodes that have the tree.
Node *& getRoot() noexcept
Return the tree's root.
Node * search(const Key &key) const noexcept
Search a key.
Node * insert(Node *p) noexcept
Insert a node into the tree.
Node * search(const Key &key) const noexcept
Search for a key in the tree.
Node *& getRoot() noexcept
Get reference to root pointer.
Node * search(const Key &key) const noexcept
Search a key in a treap.
Node *& getRoot() noexcept
Return the tree's root.
Node * insert(Node *root, Node *p) noexcept
size_t size() const noexcept
Count the number of elements of the list.
Node *& getRoot() noexcept
Get the top-down splay tree's root.
Node * insert(Node *p) noexcept
Inserts a node in a top-down splay tree.
Node * search(const Key &key) noexcept
Searches a key in a top-down splay tree.
iterator end() noexcept
Return an STL-compatible end iterator.
int preOrderRec(Node *root, void(*visitFct)(Node *, int, int))
Traverse recursively in preorder a binary tree.
int inOrderRec(Node *root, void(*visitFct)(Node *, int, int))
Traverse recursively inorder a binary tree.
void destroyRec(Node *&root) noexcept
Free recursively all the memory occupied by the tree root
size_t computeHeightRec(Node *root) noexcept
Compute recursively the height of root
Main namespace for Aleph-w library functions.
static void prefix(Node *root, DynList< Node * > &acc)
DynList< T > maps(const C &c, Op op)
Classic map operation.
Itor::difference_type count(const Itor &beg, const Itor &end, const T &value)
Count elements equal to a value.
#define RED
Red color constant (newly inserted nodes are red)
AVL binary search tree with nodes without virtual destructor.
Binary search tree with nodes without virtual destructors,.
Randomized binary search tree.
Red-black tree with nodes without virtual destructor.
Treap (a special type of randomized binary search tree) using nodes without virtual destructor.
AVL tree implementation (height-balanced BST).
Utility functions for binary tree operations.
Generic unbalanced binary search tree.
Randomized binary search tree.
Red-Black tree implementation (bottom-up balancing).
Top-down splay tree implementation (without rank support).
Treap: randomized BST combining tree and heap properties.
void write_bin(const vector< int > &values, const string &prefix)
void write_rand(const vector< int > &values, const string &prefix)
void write_avl(const vector< int > &values, const string &prefix)
static void bin_print_key(BinTree< int >::Node *p, int, int)
vector< int > generate_random_values(size_t n, unsigned int seed)
static void avl_print_key(Avl_Tree< int >::Node *p, int, int)
void write_treap(const vector< int > &values, const string &prefix)
static void treap_print_key(Treap< int >::Node *p, int, int)
void write_splay(const vector< int > &values, const string &prefix)
static void rb_write_colors(Rb_Tree< int >::Node *p, int, int)
static void splay_print_key(Splay_Tree< int >::Node *p, int, int)
void write_rb(const vector< int > &values, const string &prefix)
static void rand_print_key(Rand_Tree< int >::Node *p, int, int)
static ofstream * current_output
static void rb_print_key(Rb_Tree< int >::Node *p, int, int)