Data update

This commit is contained in:
Ingy döt Net 2024-07-13 15:19:22 -07:00
parent 29a5eea0d4
commit 5c1bb7bfa9
2011 changed files with 35081 additions and 3229 deletions

View file

@ -0,0 +1,34 @@
>>SOURCE FORMAT IS FREE
IDENTIFICATION DIVISION.
CLASS-ID. Tree INHERITS FROM Base USING X.
DATE-WRITTEN. 20240702.
ENVIRONMENT DIVISION.
CONFIGURATION SECTION.
OBJECT-COMPUTER.
MEMORY SIZE IS 1073741824 CHARACTERS.
REPOSITORY.
CLASS Base.
CLASS X.
IDENTIFICATION DIVISION.
OBJECT.
DATA DIVISION.
WORKING-STORAGE SECTION.
77 ws-value USAGE IS OBJECT REFERENCE X ONLY.
77 ws-left USAGE IS OBJECT REFERENCE Tree ONLY.
77 ws-right USAGE IS OBJECT REFERENCE Tree ONLY.
PROCEDURE DIVISION.
IDENTIFICATION DIVISION.
METHOD-ID. replace_all.
DATA DIVISION.
LINKAGE SECTION.
77 new_value USAGE IS OBJECT REFERENCE X ONLY.
PROCEDURE DIVISION USING BY REFERENCE new_value.
MOVE new_value TO ws-value.
IF ws-left IS NOT EQUAL TO NULL THEN
INVOKE ws-left "replace_all" USING BY REFERENCE new_value.
IF ws-right IS NOT EQUAL TO NULL THEN
INVOKE ws-right "replace_all" USING BY REFERENCE new_value.
GOBACK.
END METHOD replace_all.
END OBJECT.
END CLASS Tree.

View file

@ -0,0 +1,31 @@
type Node<T> = auto class
data: T;
left,right: Node<T>;
end;
function CreateTree(n: integer): Node<integer>;
begin
if n = 0 then
Result := nil
else
Result := new Node<integer>(
Random(100),
CreateTree((n-1) div 2),
CreateTree(n-1 - (n-1) div 2)
);
end;
procedure InfixTraverse<T>(root: Node<T>; act: T -> ());
begin
if root = nil then
exit;
InfixTraverse(root.left,act);
act(root.data);
InfixTraverse(root.right,act);
end;
begin
var tree := CreateTree(10);
Println(tree);
InfixTraverse(tree, x -> Print(x));
end.