diff --git a/list/list.c b/list/list.c index 5807c18..005cfa2 100644 Binary files a/list/list.c and b/list/list.c differ diff --git a/list/list_expand.c b/list/list_expand.c index 3a756bc..32c20d7 100644 --- a/list/list_expand.c +++ b/list/list_expand.c @@ -140,19 +140,19 @@ void printNodeInfo(Node *p_node, int priority) { printf("NEXT->%p / LAST->%p / MALLOC:%d\n", p_node->next, p_node->last, p_node->if_malloc); if (!strcmp(p_node->type, "int")) { for (int i = 0; i < priority + 1; i++) printf(" "); - printf("VALUE(Int):%d\n", *(int *)(p_node->value)); + printf("VALUE(int):%d\n", *(int *)(p_node->value)); } else if (!strcmp(p_node->type, "double")) { for (int i = 0; i < priority + 1; i++) printf(" "); - printf("VALUE(Double):%a\n", *(double *)(p_node->value)); + printf("VALUE(double):%a\n", *(double *)(p_node->value)); } else if (!strcmp(p_node->type, "string")) { for (int i = 0; i < priority + 1; i++) printf(" "); - printf("VALUE(String):%s\n", (char *)(p_node->value)); + printf("VALUE(string):%s\n", (char *)(p_node->value)); } else if (!strcmp(p_node->type, "pointer")) { for (int i = 0; i < priority + 1; i++) printf(" "); - printf("VALUE(Pointer):%s\n", (char *)(p_node->value)); + printf("VALUE(pointer):%s\n", (char *)(p_node->value)); } else if (!strcmp(p_node->type, "list")) { for (int i = 0; i < priority + 1; i++) printf(" "); @@ -166,23 +166,31 @@ void printNodeInfo(Node *p_node, int priority) { void printNode(Node *p_node) { printf("#NODE(location:%p, id:%llu){\n", p_node, p_node->id); printf(" "); - printf("NEXT->%p / LAST->%p / MALLOC:%d\n", p_node->next, p_node->last, p_node->if_malloc); - printf(" "); - if (!strcmp(p_node->type, "int")) { - printf("%d", *(int *)(p_node->value)); - } - else if (!strcmp(p_node->type, "double")) { - printf("%a\n", *(double *)(p_node->value)); - } - else if (!strcmp(p_node->type, "string")) { - printf("%s\n", (char *)(p_node->value)); - } - else if (!strcmp(p_node->type, "pointer")) { - printf("%s\n", (char *)(p_node->value)); - } - else if (!strcmp(p_node->type, "list")) { - printList((List *)p_node->value); + printf("NEXT->%p / LAST->%p\n", p_node->next, p_node->last, p_node->if_malloc); + for (int i = 0; i < 1; i++) printf(" "); + printf("ifMalloc: "); + if (p_node->if_malloc) { + printf("YES\n"); + for (int i = 0; i < 1; i++) printf(" "); + printf("Value(type: %s): ", p_node->type); + if (!strcmp(p_node->type, "int")) { + printf("%d", *(int *)(p_node->value)); + } + else if (!strcmp(p_node->type, "double")) { + printf("%a\n", *(double *)(p_node->value)); + } + else if (!strcmp(p_node->type, "string")) { + printf("%s\n", (char *)(p_node->value)); + } + else if (!strcmp(p_node->type, "pointer")) { + printf("%s\n", (char *)(p_node->value)); + } + else if (!strcmp(p_node->type, "list")) { + printList((List *)p_node->value); + } } + else printf("NO\n"); + printf("}\n"); } diff --git a/test.c b/test.c index 14423f9..89b0134 100644 --- a/test.c +++ b/test.c @@ -47,8 +47,9 @@ int tree(void) { addChildInRight(cl_tnode, tnodeWithInt(5)); addChildInRight(cr_tnode, tnodeWithInt(6)); addChildInRight(cr_tnode, tnodeWithInt(7)); + + removeChildByIndex(cr_tnode, 1); printTNodeWithFamily(t_tnode, 0); - //removeChildByIndex(t_tnode, 0); releaseAllForTree(); return 0; } diff --git a/tree/tree.c b/tree/tree.c index 0d42a14..9c0c123 100644 --- a/tree/tree.c +++ b/tree/tree.c @@ -250,7 +250,7 @@ TNode *getChildByIndex(TNode *p_tnode, unsigned long long index) { List *p_home = p_tnode->home; Node *p_node = p_home->head; int m_index = 0; - if (index < p_tnode->child_num - 1) + if (index < p_tnode->child_num) { while (p_node != NULL && m_index < index) { m_index++;