当前位置: 首页>>代码示例>>C++>>正文


C++ TreeNode::clear方法代码示例

本文整理汇总了C++中TreeNode::clear方法的典型用法代码示例。如果您正苦于以下问题:C++ TreeNode::clear方法的具体用法?C++ TreeNode::clear怎么用?C++ TreeNode::clear使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在TreeNode的用法示例。


在下文中一共展示了TreeNode::clear方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: randomForestClassifyThread

void* randomForestClassifyThread(void* index) {
    int number = *(int*)index;
    vector<int> result;
    set<int> attributes = getRandomAttributes();
    vector<int> samples = getRandomSampleIndexs();
    TreeNode* tree = buildDecisionTree(samples, attributes, samples);
    for (int j = 0; j < allTests.size(); j++) {
        result.push_back(findPath(tree, allTests[j]));
    }
    cout << number << endl;
    results[number] = result;
    tree->clear();
    delete tree;
}
开发者ID:dengyh,项目名称:datamining,代码行数:14,代码来源:main_thread.cpp

示例2: randomForestClassify

void randomForestClassify() {
    for (int i = 0; i < TREE_NUM; i++) {
        vector<int> result;
        set<int> attributes = getRandomAttributes();
        vector<int> samples = getRandomSampleIndexs();
        TreeNode* tree = buildDecisionTree(samples, attributes, samples);
        for (int j = 0; j < allTests.size(); j++) {
            result.push_back(findPath(tree, allTests[j]));
        }
        cout << "Run tree " << i << " finish" << endl;
        results[i] = result;
        tree->clear();
        delete tree;
    }
}
开发者ID:dengyh,项目名称:datamining,代码行数:15,代码来源:main_thread.cpp

示例3: insert

 iterator insert(StoredObject&& toStore)
 {
     TreeNode* node = getNode(toStore.location);
     if (node->level() > 0)
     {
         // We store one element at time so there will be a moment before node overflow when its
         // count will be equal capacity. Then we'll relocate all its elements to the new child
         // nodes. At worst scenario, all elements will be relocated to the same node, so its
         // count() will be again equal to capacity. The loop ends when at least one element is
         // relocated to the another child node.
         while (node->count() == nodeCapacity && node->level() > 0)
         {
             typename TreeNode::iterator it;
             typename TreeNode::iterator itEnd = node->end();
             for (it = node->begin(); it != itEnd; ++it)
             {
                 node->child(it->location).insert(std::move(*it));
             }
             node->clear();
             node = &(node->child(toStore.location));
         }
     }
     return iterator(node, node->insert(std::move(toStore)));
 }
开发者ID:mgoral,项目名称:geocontainers,代码行数:24,代码来源:QuadTree.hpp

示例4: zigzagLevelOrder

 vector<vector<int> > zigzagLevelOrder(TreeNode *root) {
     
     vector<vector<int>> answer;
     
     vector<int> level;
     
     if(root==NULL) {
         return answer;
     }
     
     
     queue<TreeNode *> q;
     
     q.push(root);
     
     int num = 1;
     
     int row = 0;
     
     TreeNode *temp;
     
     while(!q.empty()){
         
         temp = q.front();
         
         q.pop();
        
         level.push_back(temp->val);
         
         num--;
         
             
         if(temp->left!=NULL){
             q.push(temp->left);
         }
         
         if(temp->right!=NULL){
             q.push(temp->right);
         }
             
        
         
         if(num==0){
             
             
             num = q.size();
             
             if(row%2==0){
                 
                 answer.push_back(level);
             }else{
                 
                 vector<int> temp;
                 for(int i = level.size() - 1 ; i >= 0; --i) {
                     temp.push_back(level[i]);
                 }
                 answer.push_back(temp);
                 temp.clear();
             }
             
             level.clear();
             
             row++;
             
         }
         
     }
     
     return answer;
 }
开发者ID:cloudmonkeypeng,项目名称:LeetCode,代码行数:70,代码来源:Binary+Tree+Zigzag+Level+Order+Traversal.cpp


注:本文中的TreeNode::clear方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。