#include
#include
#define maxsize 100
typedef
struct pnode
ptnode;
typedef
struct
ptree;
ptree*
inittree()
void
creat
(ptree *t,
int n)
t->nodes[0]
.parent =-1
;}void
destorytree()
void
cleartree
(ptree *t)
//求樹的深度
inttreedepth
(ptree t)
if(max < def)
max = def;
//將樹最大深度賦值給max
}return max;
}//如果樹存在返回樹的根的值
introot
(ptree t)
//若樹存在第i個節點這返回它的值,否則返回65535
intvalue
(ptree t,
int i)
//將cur_e節點的值替換為value
intassign
(ptree *t,
int cur_e,
int value)
}return0;
}//返回cur_e的雙親
intparent
(ptree t,
int cur_e)
//若cur_e是樹中的值,則返回他的左孩子
intleftchild
(ptree t,
int cur_e)
inttreeempty
(ptree t)
intrightsibling
(ptree t,
int cur_e)
//插入子樹c作為樹t節點p後的度為i的孩子
intinsertchild
(ptree *t,
int p,
int i,ptree c)
l = k+1;
}if(ln-1)
for(k = t->n-
1;k>=l;k--
)for
(k=0
;k) t->nodes[l]
.parent = j;
t->n +
= c.n;
while
(f)}
return1;
}else
return0;
}int
main()
樹的雙親表示法
之前學習樹多是採用鍊錶的,在羊村捕羊的演算法上,採用了線性儲存,為此學習一下。雙親表示法區別於,鍊錶,是用線性陣列來存放樹的。既然是線性的,就用一維陣列來完成,開始想法是,每個陣列的元素為乙個結構體。typedef struct node n,pn 再用乙個結構體將這個線性陣列的資訊包含起來 typ...
樹的雙親表示法
演算法思想 將這兩個節點的所有祖先節點從下至上依次存放到兩個陣列中,然後遍歷這兩個陣列,第乙個相等的值便是所求值。include define maxsize 100 typedef struct ptnode ptnode 樹的節點結構 typedef struct ptree ptree 樹pt...
樹的孩子雙親表示法
新增鏈結描述 按照上述部落格,測試了一下這個程式.有兩點說說明一下.首先,博主說使用c語言,我第一次用.c檔案編譯,出現error expected or before token 這是使用了引用 而在c語言中沒有引用的概念,在c語言中是取位址符號.後期改為.cpp檔案即可執行 第二點就是 fflu...