测试与debug。

This commit is contained in:
Saturneric 2018-06-13 16:32:39 +08:00
parent 896e454c40
commit 880fa14d10
3 changed files with 133 additions and 115 deletions

16
test.c
View File

@ -37,6 +37,12 @@ int list(void) {
return 0;
}
int _useTreeThroughDown(TNode *p_tnode, unsigned long long height) {
printTNode(p_tnode,0);
return 0;
}
int tree(void) {
safeModeForTree(1);
Tree *t_tree = initTree();
@ -44,12 +50,14 @@ int tree(void) {
addChildInRight(t_tnode, cl_tnode);
addChildInRight(t_tnode, cr_tnode);
addChildInRight(cl_tnode, tnodeWithInt(4));
addChildInRight(cl_tnode, tnodeWithInt(5));
TNode *gs_tnode = tnodeWithInt(5);
addChildInRight(cl_tnode,gs_tnode);
addChildInRight(cr_tnode, tnodeWithInt(6));
addChildInRight(cr_tnode, tnodeWithInt(7));
removeChildByIndex(cr_tnode, 1);
printTNodeWithFamily(t_tnode, 0);
addChildInRight(gs_tnode, tnodeWithInt(8));
setRoot(t_tree, t_tnode);
TreeThroughUp(t_tree, _useTreeThroughDown);
//printTNodeWithFamily(t_tnode, 0);
releaseAllForTree();
return 0;
}

View File

@ -107,7 +107,7 @@ int addChildInRight(TNode *f_tnode, TNode *c_tnode) {
TNode *getBrotherInLeft(TNode *p_tnode) {
List *p_home = p_tnode->father->home;
Node *p_node = p_home->head;
Node *p_node = p_tnode->room;
unsigned long long index = getIndexByNode(p_home, p_node);
if (index > 0) return (TNode *)(findByIndexForNode(p_home, index - 1)->value);
return NULL;
@ -293,7 +293,6 @@ int removeChildByIndex(TNode *p_tnode, unsigned long long index) {
int TreeThroughUp(Tree *p_tree, int(*func)(TNode *, unsigned long long height)) {
TNode *p_tnode = p_tree->root;
if (p_tnode != NULL) {
func(p_tnode, 0);
if (p_tnode->child_num > 0) {
for (int i = 0; i < p_tnode->child_num; i++) {
if (_doTreeThroughUp(getChildByIndex(p_tnode, i), 1, func) == -1) {
@ -301,6 +300,7 @@ int TreeThroughUp(Tree *p_tree, int(*func)(TNode *, unsigned long long height))
}
}
}
func(p_tnode, 0);
}
return 0;
}
@ -320,8 +320,8 @@ int _doTreeThroughUp(TNode *p_tnode, int height, int(*func)(TNode *, unsigned lo
int TreeThroughDown(Tree *p_tree, int(*func)(TNode *, unsigned long long height)) {
TNode *p_tnode = p_tree->root;
if (p_tree->root != NULL) {
if (p_tree->root->child_num > 0) {
func(p_tnode, 0);
if (p_tree->root->child_num > 0) {
for (int i = 0; i < p_tnode->child_num; i++) {
if (_doTreeThroughDown(getChildByIndex(p_tnode, i), 1, func) == -1) {
break;

View File

@ -58,9 +58,11 @@ void *getValueByPointerForTree(TNode *p_tnode) {
}
int printTNode(TNode *p_tnode, int priority) {
if (p_tnode != NULL) {
for (int i = 0; i < priority; i++) printf(" ");
if (priority == 0) printf("###");
else printf("#");
printf("TNode(id: %llu)\n", p_tnode->id);
for (int i = 0; i < priority + 1; i++) printf(" ");
printf("ifMalloc: ");
@ -88,9 +90,12 @@ int printTNode(TNode *p_tnode, int priority) {
printf("Child number: %llu\n", p_tnode->child_num);
}
return 0;
}
return -1;
}
int printTNodeWithHome(TNode *p_tnode,int priority) {
if (p_tnode != NULL) {
if (priority == 0) printf("###");
else printf("#");
printf("TNode(id: %llu)\n", p_tnode->id);
@ -133,14 +138,17 @@ int printTNodeWithHome(TNode *p_tnode,int priority) {
List *p_home = p_tnode->home;
Node *p_node = p_home->head;
while (p_node != NULL) {
printTNode((TNode *)p_node->value,priority+2);
printTNode((TNode *)p_node->value, priority + 2);
p_node = p_node->next;
}
return 0;
}
return -1;
}
int printTNodeWithFamily(TNode *p_tnode, int priority) {
for (int i = 0; i < priority ; i++) printf(" ");
if (p_tnode != NULL) {
for (int i = 0; i < priority; i++) printf(" ");
if (priority == 0) printf("###");
else printf("#");
printf("TNode(id: %llu)\n", p_tnode->id);
@ -187,6 +195,8 @@ int printTNodeWithFamily(TNode *p_tnode, int priority) {
p_node = p_node->next;
}
return 0;
}
return -1;
}
int printTree(Tree *p_tree) {