if (!is_ancestor(Par, x, y)) return false;\r
return depth(Par, x) == (depth(Par, y) + 1);\r
}\r
-\r
+bool XMLTree::IsFirstChild(treeNode x){\r
+ return ((x != NULLT)&&(x==Root() || prev_sibling(Par,x) == NULLT));\r
+}\r
// NumChildren(x): number of children of node x. Constant time with the data structure\r
// of Sadakane.\r
int XMLTree::NumChildren(treeNode x) \r
return first_child(Par, x);\r
}\r
\r
+treeNode XMLTree::LastChild(treeNode x) \r
+{\r
+ if (x == Root() || isleaf(Par,x) || x == NULLT)\r
+ return x;\r
+ else\r
+ return find_open(Par,find_close(Par,parent(Par,x))-1);\r
+}\r
+\r
// NextSibling(x): returns the next sibling of node x, assuming it exists.\r
treeNode XMLTree::NextSibling(treeNode x) \r
{\r
\r
/** IsChild(x,y): returns whether node x is parent of node y. */\r
bool IsChild(treeNode x, treeNode y);\r
+\r
+ /** IsChild(x,y): returns whether node x is the first child of its parent */\r
+ bool IsFirstChild(treeNode x);\r
\r
/** NumChildren(x): number of children of node x. Constant time with the \r
* data structure of Sadakane. */\r
* Very fast in BP. */\r
treeNode FirstChild(treeNode x);\r
\r
+ /** LastChild(x): returns the last child of node x. \r
+ * Implemented by Kim naively. */\r
+ treeNode LastChild(treeNode x);\r
+\r
/** NextSibling(x): returns the next sibling of node x, assuming it \r
* exists. */\r
+\r
treeNode NextSibling(treeNode x);\r
\r
/** PrevSibling(x): returns the previous sibling of node x, assuming it \r