Aleph-w 3.0
A C++ Library for Data Structures and Algorithms
Loading...
Searching...
No Matches
testBalance.C
Go to the documentation of this file.
1
2/* Aleph-w
3
4 / \ | | ___ _ __ | |__ __ __
5 / _ \ | |/ _ \ '_ \| '_ \ ____\ \ /\ / / Data structures & Algorithms
6 / ___ \| | __/ |_) | | | |_____\ V V / version 1.9c
7 /_/ \_\_|\___| .__/|_| |_| \_/\_/ https://github.com/lrleon/Aleph-w
8 |_|
9
10 This file is part of Aleph-w library
11
12 Copyright (c) 2002-2018 Leandro Rabindranath Leon
13
14 Permission is hereby granted, free of charge, to any person obtaining a copy
15 of this software and associated documentation files (the "Software"), to deal
16 in the Software without restriction, including without limitation the rights
17 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
18 copies of the Software, and to permit persons to whom the Software is
19 furnished to do so, subject to the following conditions:
20
21 The above copyright notice and this permission notice shall be included in all
22 copies or substantial portions of the Software.
23
24 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
25 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
26 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
27 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
28 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
29 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
30 SOFTWARE.
31*/
32# include <ctime>
33# include <cstdlib>
34# include <cassert>
35
36# include <iostream>
37# include <string>
38# include <aleph.H>
39# include <tpl_dynArray.H>
40# include <tpl_balanceXt.H>
41
42
43using namespace Aleph;
44using namespace std;
45
47
48void print_node(Node * p, int, int)
49{
50 cout << "(" << p->get_key() << "," << p->getCount() << ")" ;
51}
52
53
54void print_key(Node * p, int, int)
55{
56 cout << p->get_key() << " ";
57}
58
59
60int main(int argc, char *argv[])
61{
62 int n = 10;
63 if (argc > 1)
64 {
65 try
66 {
67 n = stoi(argv[1]);
68 }
69 catch (...)
70 {
71 n = 10;
72 }
73 }
74
75 if (n <= 0)
76 {
77 cerr << "Error: n must be a positive integer." << endl;
78 return 1;
79 }
80
81 unsigned int t = std::time(0);
82
83 if (argc > 2)
84 {
85 try
86 {
87 t = stoi(argv[2]);
88 }
89 catch (...)
90 {
91 t = std::time(0);
92 }
93 }
94
95 srand(t);
96
97 cout << argv[0] << " " << n << " " << t << endl;
98
99 int value = (int) (100.0*n*rand()/(RAND_MAX+1.0));
101
102 for (int i = 0; i < n - 1; i++)
103 {
104 while (1)
105 {
106 value = (int) (100.0*n*rand()/(RAND_MAX+1.0));
108 continue;
109
110 Node * p = new Node (value);
112 break;
113 }
114 }
115
117
118 cout << endl << endl;
119
120 preOrderRec(root, &print_key); cout << endl;
121
123
125
126 cout << endl << endl;
127
128 preOrderRec(root, &print_key); cout << endl;
129
131}
Core header for the Aleph-w library.
WeightedDigraph::Node Node
int main()
size_t size_t int32_t value
Definition ca-c-api.h:116
Node for extended binary search tree.
static BinNodeXt *const NullPtr
Key & get_key() noexcept
__gmp_expr< T, __gmp_binary_expr< __gmp_expr< T, U >, unsigned long int, __gmp_root_function > > root(const __gmp_expr< T, U > &expr, unsigned long int l)
Definition gmpfrxx.h:4071
size_t blossom_maximum_cardinality_matching(const GT &g, DynDlist< typename GT::Arc * > &matching, SA sa=SA())
Alias of compute_maximum_cardinality_general_matching().
Definition Blossom.H:466
int preOrderRec(Node *root, void(*visitFct)(Node *, int, int))
Traverse recursively in preorder a binary tree.
Node * insert_by_key_xt(Node *&r, Node *p, Compare &cmp) noexcept
Insert a node in an extended binary search tree.
bool check_rank_tree(Node *root) noexcept
Return true if root is a valid extended 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.
Main namespace for Aleph-w library functions.
Definition ah-arena.H:89
Node * balance_tree(Node *root)
Reequilibra un árbol binario de búsqueda.
STL namespace.
void print_node(Node *p, int, int)
Definition testBalance.C:48
void print_key(Node *p, int, int)
Definition testBalance.C:54
BinNodeXt< int > Node
Definition testBalance.C:46
Tree balancing with extended nodes.
Lazy and scalable dynamic array implementation.