40 lines
1.8 KiB
Plaintext
40 lines
1.8 KiB
Plaintext
The following shows a tree of data with nesting denoted by visual levels of indentation:
|
|
<pre>RosettaCode
|
|
rocks
|
|
code
|
|
comparison
|
|
wiki
|
|
mocks
|
|
trolling</pre>
|
|
|
|
A common datastructure for trees is to define node structures having a name and a, (possibly empty), list of child nodes. The nesting of nodes captures the indentation of the tree. Lets call this '''the nest form'''.
|
|
<pre># E.g. if child nodes are surrounded by brackets
|
|
# and separated by commas then:
|
|
RosettaCode(rocks(code, ...), ...)
|
|
# But only an _example_</pre>
|
|
|
|
Another datastructure for trees is to construct from the root an ordered list of the nodes level of indentation and the name of that node. The indentation for the root node is zero; node 'rocks is indented by one level from the left, and so on. Lets call this '''the indent form'''.
|
|
<pre>0 RosettaCode
|
|
1 rocks
|
|
2 code
|
|
...</pre>
|
|
|
|
;Task:
|
|
# Create/use a nest datastructure format and textual representation for arbitrary trees.
|
|
# Create/use an indent datastructure format and textual representation for arbitrary trees.
|
|
# Create methods/classes/proceedures/routines etc to:
|
|
## Change from a nest tree datastructure to an indent one.
|
|
## Change from an indent tree datastructure to a nest one
|
|
# Use the above to encode the example at the start into the nest format, and show it.
|
|
# transform the initial nest format to indent format and show it.
|
|
# transform the indent format to final nest format and show it.
|
|
# Compare initial and final nest formats which should be the same.
|
|
|
|
;Note:
|
|
* It's all about showing aspects of the contrasting datastructures as they hold the tree.
|
|
* Comparing nested datastructures is secondary - saving formatted output as a string then a string compare would suffice for this task, if its easier.
|
|
<br>
|
|
|
|
Show all output on this page.
|
|
|