⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 drawtree.cpp

📁 unix,linux下编译。用于蛋白质
💻 CPP
字号:
#include "muscle.h"
#include "tree.h"

/***
Simple tree drawing algorithm.

y coordinate of node is index in depth-first traversal.
x coordinate is distance from root.
***/

static unsigned DistFromRoot(const Tree &tree, unsigned uNodeIndex)
	{
	const unsigned uRoot = tree.GetRootNodeIndex();
	unsigned uDist = 0;
	while (uNodeIndex != uRoot)
		{
		++uDist;
		uNodeIndex = tree.GetParent(uNodeIndex);
		}
	return uDist;
	}

static void DrawNode(const Tree &tree, unsigned uNodeIndex)
	{
	if (!tree.IsLeaf(uNodeIndex))
		DrawNode(tree, tree.GetLeft(uNodeIndex));

	unsigned uDist = DistFromRoot(tree, uNodeIndex);
	for (unsigned i = 0; i < 5*uDist; ++i)
		Log(" ");
	Log("%d\n", uNodeIndex);

	if (!tree.IsLeaf(uNodeIndex))
		DrawNode(tree, tree.GetRight(uNodeIndex));
	}

void DrawTree(const Tree &tree)
	{
	unsigned uRoot = tree.GetRootNodeIndex();
	DrawNode(tree, uRoot);
	}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -