void prependChild(Node *node, Node *chd) { Node *fc; if (!chd) return; fc = firstChild(node); if (fc) { set_nextSibling(chd, fc); set_previousSibling(fc, chd); } set_firstChild(node, chd); while (chd) { set_parentNode(chd, node); chd = nextSibling(chd); } }
void appendChild(Node *node, Node *chd) { Node *lc; if (!chd) return; lc = lastChild(node); if (!lc) { set_firstChild(node,chd); } else { set_nextSibling(lc,chd); set_previousSibling(chd,lc); } while (chd) { lc = chd; set_parentNode(chd,node); chd = nextSibling(chd); } set_lastChild(node,lc); }