本文整理汇总了C++中tree::empty方法的典型用法代码示例。如果您正苦于以下问题:C++ tree::empty方法的具体用法?C++ tree::empty怎么用?C++ tree::empty使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tree
的用法示例。
在下文中一共展示了tree::empty方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: areMirrored
bool areMirrored(tree<int> l, tree<int> r) {
if (l.empty() && r.empty()) {
return true;
}
if (l.empty() || r.empty()) {
return false;
}
if (l.RootTree() != r.RootTree()) {
return false;
}
return areMirrored(l.LeftTree(), r.RightTree())
&& areMirrored(l.RightTree(), r.LeftTree());
}
示例2: 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;
}
}
示例3: AddItem
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;
}
示例4: sum
int sum(tree<int> & t, tree<char>&op){
int s = 0;
if (t.empty() && op.empty()) return s;
tree<int>left = t.leftTree();
tree<int>right = t.rightTree();
int sumLeft = sum(t.leftTree(), op.leftTree());
int sumrRight = sum(t.rightTree(), op.rightTree());
int result = 0;
char operation = op.rootTree();
switch (operation){
//...
}
}
示例5: topsCount
int topsCount(tree<int>& t)
{
if (t.empty()) return 0; // prazno
else if (t.LeftTree().empty() && t.RightTree().empty()) return 1; // listo // nenujno
else if (t.LeftTree().empty()) return 1 + topsCount(t.RightTree()); // ima dqsno // nenujno
else if (t.RightTree().empty()) return 1 + topsCount(t.LeftTree()); // ima lqvo // nenujno
else return 1 + topsCount(t.LeftTree()) + topsCount(t.RightTree()); // ima i lqvo i dqsno
}
示例6: treeHeight
int treeHeight(tree<int> t) {
if (t.empty()) {
return 0;
}
int leftTreeHeight = treeHeight(t.LeftTree());
int rightTreeHeight = treeHeight(t.RightTree());
return 1 + max(leftTreeHeight, rightTreeHeight);
}
示例7: countEdges
int countEdges(tree<T> t)
{
if (t.empty())
{
return 0;
}
else
{
return 1 + countEdges(t.leftTree()) + countEdges(t.rightTree());
}
}
示例8: findSumHelper
int findSumHelper(tree<int> nums, tree<char> opers)
{
if (nums.empty())
{
return 0;
}
else
{
switch (opers.getRoot()->inf)
{
case '+': return (nums.getRoot()->inf + countEdges(nums)) + findSumHelper(nums.rightTree(), opers.rightTree()) + findSumHelper(nums.leftTree(), opers.leftTree());
case '-': return (nums.getRoot()->inf - countEdges(nums)) + findSumHelper(nums.rightTree(), opers.rightTree()) + findSumHelper(nums.leftTree(), opers.leftTree());
case '*': return (nums.getRoot()->inf * countEdges(nums)) + findSumHelper(nums.rightTree(), opers.rightTree()) + findSumHelper(nums.leftTree(), opers.leftTree());
default: return 0;
}
}
}
示例9: AddItem
FILE_ITEM CFileTree::AddItem(char *absolutePath, unsigned char* handle)
{
FILE_ITEM item;
item.handle = handle;
item.bCached = false;
// If the tree is empty just add the new path as node on the top level.
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 {
// Check if the requested path belongs to an already registered parent node.
std::string sPath(absolutePath);
tree_node_<FILE_ITEM>* parentNode = findParentNodeFromRootForPath(absolutePath);
std::string splittedPath = _basename_932(sPath);
//printf("spl %s %s\n", splittedPath.c_str(), absolutePath);
item.path = new char[splittedPath.length() + 1];
strcpy_s(item.path, (splittedPath.length() + 1), splittedPath.c_str());
// If a parent was found use th parent.
if (parentNode) {
//printf("parent %s\n", parentNode->data.path);
filesTree.append_child(tree<FILE_ITEM>::iterator_base(parentNode), item);
} else {
// Node wasn't found - most likely a new root - add it to the top level.
//printf("No parent node found for %s. Adding new sibbling.", absolutePath);
item.path = new char[strlen(absolutePath) + 1];
strcpy_s(item.path, (strlen(absolutePath) + 1), absolutePath);
item.nPathLen = strlen(item.path);
filesTree.insert(tree<FILE_ITEM>::iterator_base(topNode), item);
topNode = filesTree.begin();
}
}
DisplayTree(topNode.node, 0);
return item;
}
示例10: isMirrored
bool isMirrored(tree<int> t) {
if (t.empty()) {
return true;
}
return areMirrored(t.LeftTree(), t.RightTree());
}