,关于一个多叉树的有关问题

求助,关于一个多叉树的问题

在做一个条纹图细化的时候,发现出现很多分叉毛刺,但是确实都细化成单线条了

因为我处理的是干涉条纹图,所以不会有交叉,所以是分叉的都可以砍掉

目前,我想到的是采用搜索二值图象,
形成多叉树,然后寻找两个相距最远的叶子路径

可是我授了很久,也没找到关于多叉树的类,和结构,
我不知道改如何创建一个多叉树,采用什么形势呢?

另外,如何寻找两个最大叶节点之间距离的路径,望指教。

相信各位学过图论的人应该比较容易。


------解决方案--------------------
int insert_node(struct tree_node *root, const char *path, const char *data, const char *value)
{
struct tree_node *parentnode = NULL;
struct tree_node *newnode = NULL; /* 将被插入的结点 */
struct tree_node *sibling = NULL;
struct tree_node *backsibling = NULL; /* sibling 的前一个兄弟 */

if ((NULL == root) || (NULL == path) || (NULL == data))
return -1;

get_node(root, path, &parentnode);
if (NULL == parentnode)
return -1;

newnode = (struct tree_node *)malloc(sizeof(struct tree_node));
if (NULL == newnode)
return -1;

memset(newnode, 0, sizeof(struct tree_node));
/* 初始化 */
newnode-> flag = -2;
if (data != NULL)
{
strcpy(newnode-> data, data);
newnode-> flag = NODE_IS_BRANCH;
}
if (value != NULL)
{
strcpy(newnode-> value, value);
newnode-> flag = NODE_IS_LEAF;
}

if (parentnode-> flag == NODE_IS_BRANCH) /* 如果 parentnode 是内部结点 */
{
/* 作为 parentnode 的子结点插入 */
insertnode_byparent(parentnode, newnode);
}
else if (parentnode-> flag == NODE_IS_LEAF) /* 如果 parentnode 是叶子结点 */
{
/* 作为 parentnode 的兄弟插入 */
sibling = parentnode-> nextsibling;
if (sibling == NULL)
{
parentnode-> nextsibling = newnode;

return 1;
}

while (sibling != NULL)
{
backsibling = sibling; /* 得到 sibling 的前一兄弟 */

sibling = sibling-> nextsibling;

if (sibling == NULL)
{
sibling = newnode;
backsibling-> nextsibling = sibling;

return 1;
}
}
}


return -1;
}

int get_parentnode(struct tree_node *root, const char *path, struct tree_node **parent)
{
struct tree_node *node = NULL; /* path 对应的结点 */
char *parentpath = NULL;
int len = 0;

if ((NULL == root) || (NULL == path))
return -1;

get_node(root, path, &node);
if (NULL == node)
return -1;

len = strlen(path) - strlen(node-> data);
parentpath = (char *)malloc(len);
if ((len < 2) || (NULL == parentpath))
return -1;
memset(parentpath, NULL, len);

/* 得到父结点路径 */
strncpy(parentpath, path, len-1); /* 要去掉 ": ",故要 -1 */
trim(parentpath);
get_node(root, parentpath, parent);
if (NULL == *parent)
return -1;

free(parentpath);
parentpath = NULL;

return 1;
}

char *get_parentnodepath(struct tree_node *root, const char *path)
{
struct tree_node *node = NULL; /* path 对应的结点 */
char *parentnode_path = NULL;
int len = 0;

if ((NULL == root) || (NULL == path))
return NULL;