예제 #1
0
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
0
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
0
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;
}
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
0
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
0
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
0
int countEdges(tree<T> t)
{
	if (t.empty())
	{
		return 0;
	}
	else
	{
		return 1 + countEdges(t.leftTree()) + countEdges(t.rightTree());
	}
}
예제 #8
0
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
0
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
0
bool isMirrored(tree<int> t) {
  if (t.empty()) {
    return true;
  }
  return areMirrored(t.LeftTree(), t.RightTree());
}