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


C++ nodes_t::resize方法代码示例

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


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

示例1: str2node2

void str2node2 (const std::string& str, nodes_t& node)
{
    //assert the node-id of a new node's parent is less than it
    std::vector < std::string > tokens;
    tokenize<std::string>(str, std::back_inserter(tokens));
    unsigned int len = tokens.size() / 2;
    node.resize (len);
    std::vector <int> sibling (len);
    for (unsigned int i=0; i<len; ++i){
        node[i].val = SingleString::get()->getPointer(tokens[2*i]);
        node[i].sibling = -1;
        node[i].child = -1;
        const int parent = atoi(tokens[2*i + 1].c_str()) -1;
        node[i].parent = parent;
        sibling[i] = -1;
        const unsigned int here = i;
        if (parent!=-1){
            if (node[parent].child == -1) node[parent].child = here;
            if (sibling[parent] != -1) node[sibling[parent]].sibling = here;
            sibling[parent] = here;
        };
    };
}
开发者ID:kaihuangecnu,项目名称:freqt,代码行数:23,代码来源:freqt.hpp

示例2: str2node

void str2node (const std::string& str, nodes_t& node)
{
    try {
            unsigned int len = str.size();
            unsigned int size = 0;
            std::string buf = "";
            std::vector <std::string> tmp;

            for (unsigned int i = 0; i < len; i++) {
                if (str[i] == '(' || str[i] == ')') {
                if (! buf.empty()) {
                tmp.push_back (buf);
                buf = "";
                ++size;
                }
                if (str[i] == ')') tmp.push_back (")");
                } else if (str[i] == '\t' || str[i] == ' ') { 	  // do nothing
                } else {
                buf += str[i];
                }
            }

        if (! buf.empty()) throw 2;

        node.resize (size);
        std::vector <int> sibling (size);
        for (unsigned int i = 0; i < size; ++i) {
            node[i].parent = -1;
            node[i].child = -1;
            node[i].sibling = -1;
            sibling[i] = -1;
        }

        std::vector <int> sr;
        unsigned int id = 0;
        int top = 0;

        for (unsigned int i = 0; i < tmp.size(); ++i) {
            if (tmp[i] == ")") {
                top = sr.size()-1;
                if (top < 1) continue;
                unsigned int child  = sr[top];
                unsigned int parent = sr[top-1];
                node[child].parent = parent;
                if (node[parent].child == -1) node[parent].child = child;
                if (sibling[parent] != -1) node[sibling[parent]].sibling = child;
                sibling[parent] = child;
                sr.resize (top);
            } else {
                node[id].val = SingleString::get()->getPointer(tmp[i]);
                sr.push_back (id);
                id++;
            }
        }
        return;
    }
    catch (const int) {
        std::cerr << "Fatal: parse error << [" << str << "]\n";
        std::exit (-1);
    }
}
开发者ID:kaihuangecnu,项目名称:freqt,代码行数:61,代码来源:freqt.hpp


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