44 cout << node->get_key() <<
" ";
49 cout << node->get_key() <<
" ";
54 cout << node->get_key() <<
" ";
103 unsigned int t = std::time(0);
109 n = std::stoi(
argv[1]);
112 t = std::stoi(
argv[2]);
121 cout <<
"n must be positive" <<
endl;
127 cout <<
"testBinNodeUtils " << n <<
" " << t <<
endl;
135 for (i = 0; i < n; i++)
138 node = tree.
search(value);
141 cout << value <<
" ";
187 catch (exception & e) { cout << e.what() <<
endl; }
188 catch (...) { cout <<
"Unknown exception" <<
endl; }
190 cout <<
"Level traverse" <<
endl;
193 cout << p->get_key() <<
" ";
210 for (i = 0; i < n; i++)
213 node = tree.
remove(value);
225 catch (exception & e) { cout << e.what() <<
endl; }
226 catch (...) { cout <<
"Unknown exception" <<
endl; }
241 <<
"will be recursively partitioned according to key " << value <<
endl;
249 cout <<
"|" << value <<
"| ";
260 <<
"will be iteratively partitioned according to key " << value <<
endl;
266 cout <<
"|" << value <<
"| ";
271 AH_ERROR(
"Left sides of partitions are not equal");
274 AH_ERROR(
"Right sides of partitions are not equal");
277 "Recursive partition result is identical to iterative partition"
293 cout <<
"Recursive insertion of " << n <<
" nodes at root ..." <<
endl;
295 for (i = 0; i < n; i++)
301 cout << values[i] <<
" ";
312 cout <<
"Iterative insertion of " << n <<
" nodes at root ..." <<
endl;
314 for (i = 0; i < n; i++)
319 cout << values[i] <<
" ";
329 cout <<
"Comparing recursive result with iterative ... " <<
endl;
331 cout <<
"Resulting trees are equal" <<
endl;
333 cout <<
"Resulting trees are different" <<
endl;
336 ofstream
out(
"bintree.tree");
340 ifstream
input(
"bintree.tree");
343 cout <<
"Comparing loaded tree with iterative ... " <<
endl;
345 cout <<
"Resulting trees are equal" <<
endl;
347 cout <<
"Resulting trees are different" <<
endl;
#define AH_ERROR(format, args...)
Print an error message (always enabled).
Node for binary search tree.
size_t size() const noexcept
Return the current dimension of array.
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 * remove(const Key &key) noexcept
Remove a key from the tree.
int postOrderRec(Node *root, void(*visitFct)(Node *, int, int))
Traverse recursively in postorder a binary tree.
int preOrderRec(Node *root, void(*visitFct)(Node *, int, int))
Traverse recursively in preorder a binary tree.
bool level_traverse(Node *root, Operation &operation)
Level traverse a tree and execute an operation.
bool split_key_rec(Node *&root, const typename Node::key_type &key, Node *&ts, Node *&tg, const Compare &cmp=Compare()) noexcept
Split recursively according to a key.
Node * copyRec(Node *root)
Copy recursively a tree.
void save_tree(Node *root, std::ostream &output)
Store a binary tree in a stream.
bool check_bst(Node *p, const Compare &cmp=Compare())
Return true if p is a binary search 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
Node * searchInBinTree(Node *root, const typename Node::key_type &key, const Compare &cmp=Compare()) noexcept
Search a key in a binary search tree.
Node * insert_root(Node *&root, Node *p, const Compare &cmp=Compare()) noexcept
Insert the node p as root of a binary search tree.
void split_key(Node *&root, const Key &key, Node *&l, Node *&r, const Compare &cmp=Compare()) noexcept
Split a binary search tree according to a key.
Main namespace for Aleph-w library functions.
Divide_Conquer_DP_Result< Cost > divide_and_conquer_partition_dp(const size_t groups, const size_t n, Transition_Cost_Fn transition_cost, const Cost inf=dp_optimization_detail::default_inf< Cost >())
Optimize partition DP using divide-and-conquer optimization.
bool areEquivalents(Node *t1, Node *t2, Equal &op) noexcept
Return true if trees are equivalents.
Binary search tree with nodes without virtual destructors,.
void operator()(BinNode< int > *p, istream &input) const
Key structure for DFS tree nodes.
int operator()(BinNode< int > *p) const
static void fill_postorder(BinTree< int >::Node *node, int, int pos)
static void fill_preorder(BinTree< int >::Node *node, int, int pos)
DynArray< int > postorder
static void fill_inorder(BinTree< int >::Node *node, int, int pos)
static void printNode(BinTree< int >::Node *node, int, int)
static void print_node(BinTree< int >::Node *node, int, int)
Utility functions for binary tree operations.
Generic unbalanced binary search tree.
Lazy and scalable dynamic array implementation.