本文整理汇总了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;
};
};
}
示例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);
}
}