本文整理汇总了C++中tree类的典型用法代码示例。如果您正苦于以下问题:C++ tree类的具体用法?C++ tree怎么用?C++ tree使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了tree类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: transform
/*!
* \fn static bool GenerateSubTree(const tree<HTML::Node> &tDom, const string &tagname, tree<HTML::Node> &tSubDom);
* \brief 生成子树
* \param [in]DOM原树
* \param [in]子树根节点的标签名
* \param [out]DOM子树
* \return bool
* \date 2011-06-01
* \author nanjunxiao
*/
bool Pretreat::GenerateSubTree(const tree<HTML::Node> &tDom, const std::string &tagname, tree<HTML::Node> &tSubDom)//目前只是为body使用
{
tree<HTML::Node>::iterator tIter = tDom.begin();
tree<HTML::Node>::sibling_iterator tFromIter,tToIter;
string sTagName;
for (; tIter != tDom.end(); ++tIter)
{
/*if (tIter->tagName() == tagname)
break;*/
if (tIter->isTag() )
{
sTagName = tIter->tagName();
transform(sTagName.begin(), sTagName.end(), sTagName.begin(), ::tolower);
if (sTagName == tagname)
break;
}
}
if (tIter == tDom.end() )
{
return false;
}
tFromIter = tIter;
tToIter = tDom.next_sibling(tFromIter);
tDom.subtree(tSubDom, tFromIter, tToIter);
return true;
}
示例2: allsuff
//--------------------------------------------------
//get sufficients stats for all bottom nodes
void allsuff(std::vector<std::vector<double> >& X,
tree& x, xinfo& xi, dinfo& di, tree::npv& bnv,
std::vector<sinfo>& sv)
{
tree::tree_cp tbn; //the pointer to the bottom node for the current observations
size_t ni; //the index into vector of the current bottom node
double* xx = new double[di.n_cov];
double y; //current y
bnv.clear();
x.getbots(bnv);
typedef tree::npv::size_type bvsz;
bvsz nb = bnv.size();
sv.resize(nb);
std::map<tree::tree_cp,size_t> bnmap;
for(bvsz i=0;i!=bnv.size();i++) bnmap[bnv[i]]=i;
for(size_t i=0;i<di.n_samp;i++) {
for(size_t j=0;j<di.n_cov; j++){
xx[j] = X[i][j];
}
y=di.y[i];
tbn = x.bn(xx,xi);
ni = bnmap[tbn];
++(sv[ni].n);
sv[ni].sy += y;
sv[ni].sy2 += y*y;
}
}
示例3: followingPath
tree_node_<FILE_ITEM>* CFileTree::findNodeWithPathFromNode(std::string path, tree_node_<FILE_ITEM>* node)
{
tree<FILE_ITEM>::sibling_iterator sib = filesTree.begin(node);
tree<FILE_ITEM>::sibling_iterator end = filesTree.end(node);
bool currentLevel = true;
std::string currentPath = path.substr(0, path.find('\\'));
size_t position = path.find('\\');
std::string followingPath("");
if (position != std::string::npos) {
followingPath = path.substr(path.find('\\') + 1);
currentLevel = false;
}
while (sib != end) {
if (strcmp(sib->path, currentPath.c_str()) == 0) {
if (currentLevel) {
return sib.node;
}
else {
return findNodeWithPathFromNode(followingPath, sib.node);
}
}
++sib;
}
return NULL;
}
示例4: fillAllNodesNames
void fillAllNodesNames(Vstring& Vnames,const tree& tr){
vector<tree::nodeP> vAllNodes;
tr.getAllNodes(vAllNodes,tr.getRoot());
Vnames.resize(vAllNodes.size());
for (int i = 0; i<vAllNodes.size();++i)
Vnames[vAllNodes[i]->id()] = vAllNodes[i]->name();
}
示例5: strcpy_s
FILE_ITEM CFileTree::AddItem(char *absolutePath, unsigned char* handle)
{
FILE_ITEM item;
item.handle = handle;
item.bCached = false;
if (filesTree.empty()) {
item.path = new char[strlen(absolutePath) + 1];
strcpy_s(item.path, (strlen(absolutePath) + 1), absolutePath);
item.nPathLen = strlen(item.path);
filesTree.set_head(item);
topNode = filesTree.begin();
}
else {
std::string sPath(absolutePath);
tree_node_<FILE_ITEM>* parentNode = findParentNodeFromRootForPath(absolutePath);
std::string splittedPath = sPath.substr(sPath.find_last_of('\\') + 1);
item.path = new char[splittedPath.length() + 1];
strcpy_s(item.path, (splittedPath.length() + 1), splittedPath.c_str());
if (parentNode) {
filesTree.append_child(tree<FILE_ITEM>::iterator_base(parentNode), item);
} else {
//printf("Parent node found for %s", absolutePath);
}
}
DisplayTree(topNode.node, 0);
return item;
}
示例6: build_tree
void build_tree(int L, int R) {
if(L == R) return;
int mid = (L + R)/2;
left = new tree; left->build_tree(L, mid);
right = new tree; right->build_tree(mid + 1, R);
}
示例7: list_if
int list_if(tree<int> &T,
list<int> &L,
bool (*pred)(int)) {
L.clear();
if (T.begin()!=T.end())
list_if(T,T.begin(),L,pred);
}
示例8: writeSiblingsXML
void writeSiblingsXML(const tree<AstNode>& t, const tree<AstNode>::iterator iRoot, ostream& stream)
{
if(t.empty())
return;
if (iRoot->getType() == "root") {
tree<AstNode>::sibling_iterator iChildren = t.begin(iRoot);
stream << "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>" << endl;
writeSiblingsXML(t,iChildren,stream);
}
else if (t.number_of_children(iRoot) == 0) {
string type = iRoot->getType();
stream << "<php:" << type << '>';
if (iRoot->getValue().length() > 0)
stream << htmlentities(iRoot->getValue());
stream << "</php:" << type << '>' << endl;
}
else {
string type = iRoot->getType();
string xmlns="";
if (type == "start")
xmlns = " xmlns:php=\"http://php.net/csl\"";
stream << "<php:" << type << xmlns << '>' << endl;
int siblingNum;
tree<AstNode>::sibling_iterator iChildren;
for (iChildren = t.begin(iRoot), siblingNum = 0; iChildren != t.end(iRoot); ++iChildren)
{
writeSiblingsXML(t,iChildren,stream);
}
stream << "</php:" << type << '>' << endl;
}
}
示例9: findNodeWithPathFromNode
tree_node_<FILE_ITEM>* CFileTree::findNodeWithPathFromNode(std::string path, tree_node_<FILE_ITEM>* node)
{
tree<FILE_ITEM>::sibling_iterator sib = filesTree.begin(node);
tree<FILE_ITEM>::sibling_iterator end = filesTree.end(node);
bool currentLevel = true;
std::string currentPath = _first_dirname(path);
size_t position = currentPath.size();
std::string followingPath = _following_path(path);
currentLevel = followingPath.empty();
while (sib != end) {
// printf("sib->path '%s' lv %d curpath '%s' follow '%s'\n", sib->path, currentLevel, currentPath.c_str(), followingPath.c_str());
if (strcmp(sib->path, currentPath.c_str()) == 0) {
if (currentLevel) {
return sib.node;
}
else {
return findNodeWithPathFromNode(followingPath, sib.node);
}
}
++sib;
}
return NULL;
}
示例10: treeToJava
void treeToJava(JNIEnv * env, const tree<J_NVItem>::iterator_base & it, jobject & jnode, const JMultiTreeNode & fields)
{
// LOGI("Enter %s %p\n",__FUNCTION__,&it);
//转换当前节点
fields.cpp2Java(env, *it, jnode);
//处理子节点
tree<J_NVItem>::children_iterator itc = it.begin_children_iterator();
tree<J_NVItem>::children_iterator eitc = it.end_children_iterator();
//jclass clsNode = env->FindClass(JCLSNAME_TreeNode);
jclass clsArrayList = env->FindClass(JCLSNAME_ArrayList);
jmethodID add_mid = env->GetMethodID(clsArrayList,"add","(Ljava/lang/Object;)Z");
//当前节点孩子列表
jobject childList = env->GetObjectField(jnode, fields.m_Childs_id);
while(itc != eitc)
{
//创建java子节点
jobject jchild = env->NewObject(gClsTreeNode, fields.m_Construct_mid);
//转换子节点
treeToJava(env, itc, jchild, fields);
//添加子节点到当前节点孩子列表
env->CallBooleanMethod(childList, add_mid, jchild);
env->DeleteLocalRef(jchild);
++itc;
}
env->DeleteLocalRef((jobject)clsArrayList);
env->DeleteLocalRef(childList);
// LOGI("Leave %s %p\n",__FUNCTION__, &it);
}
示例11: count_if
//---:---<*>---:---<*>---:---<*>---:---<*>---:---<*>
int count_if(tree<int> &T,tree<int>::iterator n,
bool (*pred)(int)) {
int count = pred(*n);
tree<int>::iterator c = n.lchild();
while (c!=T.end())
count += count_if(T,c++,pred);
return count;
}
示例12: WeaveNet
void WeaveNet(SQcont<T> const &incont, tree<T> &outnet)
{
outnet.clear();
auto top(outnet.begin());
auto now(outnet.insert(top, *incont.cbegin()));
for(auto c = incont.cbegin()+1;c != incont.cend();++c)
now = outnet.append_child(now, *c);
}
示例13: GenerateSubTree
/*!
* \fn static void GenerateSubTree(const tree<HTML::Node> &tDom, const tree<HTML::Node>::iterator &tIter, tree<HTML::Node> &tSubDom);
* \brief 生成子树
* \param [in]DOM原树
* \param [in]子树根节点的迭代器
* \param [out]DOM子树
* \return void
* \date 2011-06-01
* \author nanjunxiao
*/
void Pretreat::GenerateSubTree(const tree<HTML::Node> &tDom, const tree<HTML::Node>::iterator &tIter, tree<HTML::Node> &tSubDom)
{
tree<HTML::Node>::sibling_iterator tFromIter,tToIter;
tFromIter = tIter;
tToIter = tDom.next_sibling(tFromIter);
tDom.subtree(tSubDom, tFromIter, tToIter);
}
示例14: main
int main()
{
#ifndef ONLINE_JUDGE
freopen(TASK".in","r",stdin);
freopen(TASK".out","w",stdout);
#endif
ios::sync_with_stdio(0);
cin.tie(0);
unordered_map<int,int> cnt[2];
int n;
cin>>n;
vector<int> a(n);
for(auto &it:a) cin>>it;
vector<int> pre(n),suf(n);
for(int i=0;i<n;i++)
{
pre[i]=cnt[0][a[i]]++;
suf[n-i-1]=cnt[1][a[n-i-1]]++;
}
long long ans=0;
for(int i=1;i<n;i++)
{
me.insert({pre[i-1],i-1});
ans+=i-me.order_of_key({suf[i],i});
}
cout<<ans<<endl;
}
示例15: main
int main(int argc, char** argv){
// t.init();
#define WITH_GL
#ifdef WITH_GL
init(argc, argv);
glutMouseFunc(mouse);
glutTimerFunc(1000/60, mainLoop, 1);
glutMainLoop();
#endif
for(int i = 0; i < 1195; i++){
// t.grow();
#ifdef WITH_GL
t.draw();
#else
t.transport(); // jedna tura gry
if(i%192 == 0){
std::cout << "round " << i/192 << "\n\n";
t.print();
std::cout << std::endl;
std::cout << std::endl;
std::cout << std::endl;
}
// getchar();
#endif
}
return 0;
}