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)
311 cout <<
" Written: " <<
prefix <<
"avl.Tree" <<
endl;
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)
410 cout <<
" Written: " <<
prefix <<
"splay.Tree" <<
endl;
437 for (
int val : values)
439 if (tree.
search(val) ==
nullptr)
452 cout <<
" Written: " <<
prefix <<
"treap.Tree" <<
endl;
479 for (
int val : values)
481 if (tree.
search(val) ==
nullptr)
493 <<
", Nodes: " << tree.
size() <<
endl;
494 cout <<
" Written: " <<
prefix <<
"rand.Tree" <<
endl;
521 for (
int val : values)
523 if (tree.
search(val) ==
nullptr)
536 cout <<
" Written: " <<
prefix <<
"bin.Tree" <<
endl;
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();
580 string type =
typeArg.getValue();
586 cout <<
"=== Tree Structure Generator ===" <<
endl;
587 cout <<
"Elements: " << n <<
", Seed: " <<
seed <<
endl;
588 cout <<
"Type: " << type <<
endl <<
endl;
593 cout <<
"Generated " << values.size() <<
" unique values" <<
endl <<
endl;
596 if (type ==
"all" || type ==
"avl")
598 cout <<
"AVL Tree:" <<
endl;
602 if (type ==
"all" || type ==
"rb")
604 cout <<
"Red-Black Tree:" <<
endl;
608 if (type ==
"all" || type ==
"splay")
610 cout <<
"Splay Tree:" <<
endl;
614 if (type ==
"all" || type ==
"treap")
616 cout <<
"Treap:" <<
endl;
620 if (type ==
"all" || type ==
"rand")
622 cout <<
"Rand Tree:" <<
endl;
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
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
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.
size_t blossom_maximum_cardinality_matching(const GT &g, DynDlist< typename GT::Arc * > &matching, SA sa=SA())
Alias of compute_maximum_cardinality_general_matching().
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)
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 a 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)