algorithm - Multiway tree construction from a node string -
There is a wonderful problem called ninety-nine, the problem is specified in the P70 header. And here is a great promotion of this problem which only takes 5 lines. However, my understanding of prologue is limited.
How does this solution appear in a C-like form (no Iitirolls available)?
Edit by request I hope I do not violate copyright.
Problem:
Syntax in BNF:
tree: = letter one '^' forest:: = | Tree forest
A good solution using inter alia:
tree (ts, t): - atom (ts), !, atom_chairs ( TS, TL), tree_d (TL- [], T). % (+,?) Tree (ts, t): - nonveir (t), tree_d (tl- [], t), atom_church (ts, tl). % (?, +) Tree_d ([x | f1] -t, t (x, f)): - one_d (f1 - ['^' | t], f) one_d (ff, [] ) One_D (F1-F3, [TF]): - Tree_D (F1-F2, T), One_D (F2-F3, F).
problem definition
(taken from)
We believe that the node of the multivace tree has a single character. In the sequence sequence before the depth of your nodes, whenever a particular character is ^
during the tree, this step is backwards at the previous level.
According to this rule, the tree is represented in the figure: afg ^^ c ^ bd ^ e ^^^
Define the syntax of the string and one wordicate This is a stack Is easy with This is a pseudocode: A dummy The opposite direction is a simple recursive case: As specified in the problem, whenever we go back to the previous level, we include the Type tree (string, tree))
tree
when string
is given to create . Work with atoms (instead of stars) in both directions.
Solution Part 1:
String2Tree
function string 2 tree (string stroke): tree light st new stack & lieutenant; Node & gt; Please Root New Nude Stats. Process (Route) FOREACH EL IN ST IF L 'IS' ST.pop () ELSE take baby new-node (L) LET Top ST.top (top) top.adopt (child) St.Push (child) Returns New -Tree (root)
root
node simplifies cases using. Basically the algorithm is as follows:
< Li>
the solution part 2:
Tree2String
function string (tree T): string late sb. New-Stringbuffer Visit (T.ROT, SB) Returns New-String (SB) Proceedings of Execution (Node N, Stringbuffer SB) sb.append (n.label) NK Children () for Children () Travel (Children, SB) Sb.append ('^')
^
.
Comments
Post a Comment