How to resolve the algorithm Visualize a tree step by step in the Prolog programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Visualize a tree step by step in the Prolog programming language

Table of Contents

Problem Statement

A tree structure   (i.e. a rooted, connected acyclic graph)   is often used in programming.
It's often helpful to visually examine such a structure. There are many ways to represent trees to a reader, such as: Write a program to produce a visual representation of some tree.
The content of the tree doesn't matter, nor does the output format, the only requirement being that the output is human friendly. Make do with the vague term "friendly" the best you can.

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Visualize a tree step by step in the Prolog programming language

Source code in the prolog programming language

% direction may be horizontal/vertical/list
display_tree(Direction) :-
	sformat(A, 'Display tree ~w', [Direction]),
	new(D, window(A)),
	send(D, size, size(350,200)),
	new(T, tree(text('Root'))),
	send(T, neighbour_gap, 10),
	new(S1, node(text('Child1'))),
	new(S2, node(text('Child2'))),
	send_list(T, son,[S1,S2]),
	new(S11, node(text('Grandchild1'))),
	new(S12, node(text('Grandchild2'))),
	send_list(S1, son, [S11, S12]),
	new(S21, node(text('Grandchild3'))),
	new(S22, node(text('Grandchild4'))),
	send_list(S2, son, [S21, S22]),
	send(T, direction, Direction),
	send(D, display, T),
	send(D, open).


  

You may also check:How to resolve the algorithm Levenshtein distance/Alignment step by step in the Scala programming language
You may also check:How to resolve the algorithm Array length step by step in the Quackery programming language
You may also check:How to resolve the algorithm Deconvolution/2D+ step by step in the Raku programming language
You may also check:How to resolve the algorithm Binary strings step by step in the PARI/GP programming language
You may also check:How to resolve the algorithm Stack step by step in the M2000 Interpreter programming language