Added IsFirstChild and LastChild
[SXSI/XMLTree.git] / XMLTree.cpp
index 99d0395..249143c 100644 (file)
@@ -357,7 +357,9 @@ bool XMLTree::IsChild(treeNode x, treeNode y)
     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
@@ -499,6 +501,14 @@ treeNode XMLTree::FirstChild(treeNode x)
     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