+// TaggedNext(x,tag): returns the first node tagged tag with larger preorder than x \r
+// Returns NULLT if there is none.\r
+treeNode XMLTree::TaggedNext(treeNode x, TagType tag) \r
+ {\r
+ if (!finished) {\r
+ fprintf(stderr, "Error: data structure has not been constructed properly\n");\r
+ exit(1);\r
+ }\r
+\r
+ int r, s;\r
+ treeNode y;\r
+ if (x==NULLT)\r
+ return NULLT;\r
+\r
+ r = (int) Tags->rank(tag, node2tagpos(x));\r
+ s = (int) Tags->select(tag, r+1);\r
+ if (s == -1) return NULLT; // there is no such node\r
+ y = tagpos2node(s); // transforms the tag position into a node position \r
+ return (y<=x ? NULLT : y);\r
+ }\r
+\r
+\r