<class> <name> ... </name> <room> ... </room> <days> ... </days> </class>
/class/name/following-sibling::*

(& (objectClass = person) (| (givenName = John) (mail = john*)))
int main()
std::string emsg
nary_tree t = input_tree(std::cin, emsg)
if not emsg.empty()
std::cerr << "! " << emsg << ".\n"
exit(EXIT_FAILURE)
path_pattern pp
while input_path_pattern(std::cin, pp)
output_matches(
std::cout, match_paths(t, pp))
|
|
green
red
blue
white
|
|
nary-tree
tree-input(istream & is, string & emsg)
node-data nd
read-node-data(is, nd, emsg)
const unsigned indent = nd.indent
nary-tree t = nary-tree(nd.label)
while peek-node-data(is, nd, emsg) and
nd.indent > indent
t.add-child(tree-input(is, emsg))
return t
nary-tree input-tree(istream & is)
if ¬peek-node-data(is, nd)
return nary-tree()
const nary-tree t = tree-input(is)
if peek-node-data(is, nd)
emsg = "Root with a sibling or parent"
return t
|
match(t, p, i)
if p.size == i
found a match
else if t.label = p[i]
for c in t.children
match(c, p, i + 1)
* matches any label.
match(t, p, i)
if p.size == i
// found a match.
else if t.label = p[i] ∨ "*" == p[i]
for c in t.children
match(c, p, i + 1)
match(t, p, i, mtch) if p.size == i // mtch is the complete match. else if t.label == p[i] ∨ "*" = p[i] mtch = mtch + " " + t.label for c in t.children match(c, p, i + 1, mtch)
match(t, p, i, mtch)
if p.size == i
// mtch is the complete match.
else if t.label == p[i] ∨ "*" == p[i]
mtch = mtch + t.label
for c in t.children
match(c, p, i + 1, mtch)
for c in t.children
match(c, p, 0, "")
class nary-tree {
string label
sequence children
}
trees and no patterns
patterns and no trees
trees with root parents or siblings
| Tests | ||||||||||||||||||
| 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | |
| 1 | ||||||||||||||||||
| 2 | ||||||||||||||||||
| 3 | ||||||||||||||||||
*** Empty tree with path patterns Input (between the --- lines): --- red * --- Expected output (between the --- lines): --- --- Actual output (between the --- lines): --- ! Error! No input! ---
*** Two-node tree with no two-node match Input (between the --- lines): --- red blue blue red --- Expected output (between the --- lines): --- --- Actual output (between the --- lines): --- [none] ---
// Finds the appropriate place to put a // node in a tree that already has a root. void findSpace( nodePtr& root, nodePtr& newNode, int& numberOfNodes, int& treeDepth)
|
|