Data update

This commit is contained in:
Ingy dot Net 2024-04-19 16:56:29 -07:00
parent 0df55f9f24
commit aec8ed51b6
1045 changed files with 18889 additions and 2777 deletions

View file

@ -1,6 +1,5 @@
template<class T>
class tree
{
template<typename T>
class tree {
T value;
tree *left;
tree *right;

View file

@ -1,9 +1,8 @@
template<class T>
void tree<T>::replace_all (T new_value)
{
void tree<T>::replace_all(T new_value) {
value = new_value;
if (left != NULL)
left->replace_all (new_value);
if (right != NULL)
right->replace_all (new_value);
if (left != nullptr)
left->replace_all(new_value);
if (right != nullptr)
right->replace_all(new_value);
}

View file

@ -0,0 +1,20 @@
Type BinaryTree
valor As Integer
izda As BinaryTree Ptr
dcha As BinaryTree Ptr
End Type
Sub PrintTree(t As BinaryTree Ptr, depth As Integer)
If t = 0 Then Exit Sub
Print String(depth, Chr(9)); t->valor
PrintTree(t->izda, depth + 1)
PrintTree(t->dcha, depth + 1)
End Sub
Dim As BinaryTree b = Type(6)
Dim As BinaryTree bLeft = Type(5)
Dim As BinaryTree bRight = Type(7)
b.izda = @bLeft
b.dcha = @bRight
PrintTree(@b, 0)

View file

@ -0,0 +1,18 @@
% Tree Definition
tree(leaf(_)).
tree(branch(Left, Right)) :- tree(Left), tree(Right).
% Definition of the addone function
addone(X, Y) :- Y is X + 1.
% Definition of treewalk
treewalk(leaf(Value), Func, leaf(NewValue)) :- call(Func, Value, NewValue).
treewalk(branch(Left, Right), Func, branch(NewLeft, NewRight)) :-
treewalk(Left, Func, NewLeft),
treewalk(Right, Func, NewRight).
% Execution
run :-
X = branch(leaf(2), branch(leaf(3),leaf(4))),
treewalk(X, addone, Y),
write(Y).