From d87e7e1f1b13629489839354f7a6f787494fab41 Mon Sep 17 00:00:00 2001 From: MapleSign <347495867@qq.com> Date: Mon, 12 Feb 2018 18:07:28 +0800 Subject: [PATCH 01/31] Replace 'srand' with 'srandom' in order to match 'random'. --- list/list.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/list/list.h b/list/list.h index 66b3f9f..7209033 100644 --- a/list/list.h +++ b/list/list.h @@ -108,7 +108,7 @@ int init_value(Node *p_node,const char *type,void * p_value){ } void rand_init(void){ - srand((unsigned)time(NULL)); + srandom((unsigned)time(NULL)); } unsigned long long getId(void){ From 04718f312d7058243b70938e8c439a1974ee1f43 Mon Sep 17 00:00:00 2001 From: Saturneric Date: Sun, 18 Feb 2018 11:39:45 +0800 Subject: [PATCH 02/31] Define some functions in list_east.h --- list/list_easy.h | 66 ++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 61 insertions(+), 5 deletions(-) diff --git a/list/list_easy.h b/list/list_easy.h index 5df9833..fe3d50d 100644 --- a/list/list_easy.h +++ b/list/list_easy.h @@ -4,11 +4,67 @@ #define LIST_EASY_H Node *new_nodeWithInt(int); -Node *new_nodeWithFloat(int); -Node *new_nodeWithString(int); +Node *new_nodeWithDouble(double); +Node *new_nodeWithString(const char *); Node *new_nodeWithPointer(void *); -Node *find_nodeByInt(int); -Node *find_nodesByInt(int); -int list_through(List *p_list,void *p_func(void *));//Go through the list.Call p_func every time. +Node *find_nodeByIndex(List *, unsigned long long); +int list_through(List *p_list, int (*p_func)(void *, const char *));//Go through the list.Call p_func every time. + +Node *new_nodeWithInt(int m_int){ + int *p_int = (int *)malloc(sizeof(int)); + *p_int = m_int; + Node *p_node = init_node(); + init_value(p_node,"int",(void *)p_int); + return p_node; +} + +Node *new_nodeWithDouble(double m_double){ + double *p_double = (double *)malloc(sizeof(double)); + *p_double = m_double; + Node *p_node = init_node(); + init_value(p_node,"double",(void *)p_double); + return p_node; +} + +Node *new_nodeWithString(const char *m_string){ + char *p_string = (char *)malloc(sizeof(char)*(strlen(m_string)+1)); + strcpy(p_string,m_string); + Node *p_node = init_node(); + init_value(p_node,"string",(void *)p_string); + return p_node; +} + +Node *new_nodeWithPointer(void *m_pointer){ + Node *p_node = init_node(); + init_value(p_node,"pointer",(void *)m_pointer); + return p_node; +} + +Node *find_nodeByIndex(List *p_list, unsigned long long m_index){ + Node *p_node = p_list->head; + for(unsigned long long i= 0; i < m_index; i++){ + p_node = p_node->next; + } + return p_node; +} + +int list_through(List *p_list, int (*p_func)(void *, const char *)){ + Node *p_node = p_list->head; + while(p_node != NULL){ + if(p_node->if_setvalue == 1){ + int m_return = (*p_func)(p_node->value, p_node->type); + if (m_return == -1) break; + else if (m_return == 1){ + p_node = p_node->last; + continue; + } + else{ + + } + } + p_node = p_node->next; + } + return 0; +} #endif From ef34fa2d84199e82db8fa182956d08edf28cf0b7 Mon Sep 17 00:00:00 2001 From: Saturneric Date: Sun, 18 Feb 2018 14:32:58 +0800 Subject: [PATCH 03/31] Modefied and added Modefied list_easy.h and add error.h and error.c. --- error/error.c | 6 ++++++ error/error.h | 42 ++++++++++++++++++++++++++++++++++++++++++ list/list_easy.h | 2 ++ 3 files changed, 50 insertions(+) create mode 100644 error/error.c create mode 100644 error/error.h diff --git a/error/error.c b/error/error.c new file mode 100644 index 0000000..424eb23 --- /dev/null +++ b/error/error.c @@ -0,0 +1,6 @@ +#include "error.h" + +int main(int argc, char **argv){ + + return 0; +} diff --git a/error/error.h b/error/error.h new file mode 100644 index 0000000..7267fb3 --- /dev/null +++ b/error/error.h @@ -0,0 +1,42 @@ +#include "../list/list_easy.h" +#include + +#ifndef ERROR_H +#define ERROR_H + +#define HIGH 0x3 +#define STANDARD 0x2 +#define LOW 0x1 + +typedef struct Info{ + char *head; + char *body; + char *tail; +}Info; + +typedef struct Error{ + unsigned int type; + int pri; + Info info; + time_t time; +}Error; + +typedef struct Notice{ + unsigned int type; + Info info; + time_t time; +}Notice; + +typedef struct Log{ + FILE *fp; + int if_enable; + unsigned long int id; + unsigned int type; +}Log; + +List *error_list; +List *log_list; + + + +#endif diff --git a/list/list_easy.h b/list/list_easy.h index fe3d50d..e35c68e 100644 --- a/list/list_easy.h +++ b/list/list_easy.h @@ -67,4 +67,6 @@ int list_through(List *p_list, int (*p_func)(void *, const char *)){ } return 0; } + + #endif From 7fca55bf3e569b870a34d4a1e28f4fd5c535000a Mon Sep 17 00:00:00 2001 From: Saturneric Date: Sun, 18 Feb 2018 19:22:12 +0800 Subject: [PATCH 04/31] Defined and added. --- error/error.h | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/error/error.h b/error/error.h index 7267fb3..e9499a1 100644 --- a/error/error.h +++ b/error/error.h @@ -23,7 +23,7 @@ typedef struct Error{ typedef struct Notice{ unsigned int type; - Info info; + Info *info; time_t time; }Notice; @@ -34,9 +34,26 @@ typedef struct Log{ unsigned int type; }Log; -List *error_list; -List *log_list; +List *error_list = NULL; +List *log_list = NULL; +int if_error = 0; +int error_init(int if_enable); +int set_logDirectory(char *); +int push_error(unsigned int type, int pri, Info *p_info); +int push_notice(unsigned int type, Info *p_info); +int save_error(Error *p_error); +int save_notice(Notice *p_notice); +Info *init_Info(char *m_info); +int error_init(int if_enable){ + if(if_enable == 1){ + error_list = init_list(); + log_list = init_list(); + if_error = 1; + return 1; + } + return 0; +} #endif From 66b3ab551f289b166afc8c4890c7f2ef42ca346d Mon Sep 17 00:00:00 2001 From: Saturneic Date: Sat, 9 Jun 2018 15:57:19 +0800 Subject: [PATCH 05/31] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=BC=8F=E6=B4=9E?= =?UTF-8?q?=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- {list => ZE-Standard-Libraries/list}/list.c | 3 +- {list => ZE-Standard-Libraries/list}/list.h | 112 +++++++++++++++--- .../list}/list_easy.h | 0 3 files changed, 94 insertions(+), 21 deletions(-) rename {list => ZE-Standard-Libraries/list}/list.c (90%) rename {list => ZE-Standard-Libraries/list}/list.h (72%) rename {list => ZE-Standard-Libraries/list}/list_easy.h (100%) diff --git a/list/list.c b/ZE-Standard-Libraries/list/list.c similarity index 90% rename from list/list.c rename to ZE-Standard-Libraries/list/list.c index 7a7a4c4..582fd0c 100644 --- a/list/list.c +++ b/ZE-Standard-Libraries/list/list.c @@ -25,8 +25,7 @@ int main(int argc, char **argv){ int *f_i = (int *)malloc(sizeof(int)); *f_i = 3; - char *f_s = "there"; - Node *f_node = findByValue(t_list,"int",(void *)f_i); + //releaseMalloc(); releaseAll(); return 0; diff --git a/list/list.h b/ZE-Standard-Libraries/list/list.h similarity index 72% rename from list/list.h rename to ZE-Standard-Libraries/list/list.h index 7209033..d4ed1f7 100644 --- a/list/list.h +++ b/ZE-Standard-Libraries/list/list.h @@ -7,23 +7,28 @@ #define LIST_H typedef struct Node{ - unsigned long long id; + unsigned long long id;//唯一标识符 void *value; - int if_setvalue; - const char *type; + int if_setvalue;//记录是否已经初始化值 + const char *type;//记录值的类型 struct Node *next; struct Node *last; }Node; typedef struct List{ + unsigned long long id;//唯一标识符 Node *head; Node *tail; - unsigned long long length; + unsigned long long length;//链表长度 }List; -int safeMode(int ifon);//Safe mode is used to make sure that all malloced will be freed. -int releaseAll(void); +int safeMode(int ifon);//安全模式确保显式声明过的内存都会被释放 +int releaseMalloc(void);//释放所有声明过的内存 +int releaseSingleList(List *p_list); +int releaseSingleNode(List *p_list); +int releaseAll(void);//安全模式最后调用的函数 + List *init_list(void); Node *init_node(void); int init_value(Node *,const char *,void *); @@ -44,23 +49,32 @@ unsigned long long len(List *p_list); Node *findById(List *p_list, const unsigned long long id); Node *findByValue(List *p_list, const char *type, const void *value); -List *mply_findByValue(List *p_list, const char *type, const void *value); +List *mply_findByValue(List *p_list, const char *type, const void *value);//寻找多个值匹配的节点 int releaseList(List *p_list); int releaseNode(Node *p_node); int isListEmpty(List *p_list); -/*Something about safe mode*/ +/*有关安全模式的变量*/ int if_safeMode = 0; -List *node_list = NULL; //Store nodes which haven't been freed. -List *list_list = NULL; //Store lists which haven't been freed. +List *node_list = NULL; //储存声明过的节点. +List *list_list = NULL; //储存声明过的链表. int safeMode(int ifon){ if(ifon == 1){ if (node_list == NULL && list_list == NULL){ node_list = (List *)malloc(sizeof(List)); list_list = (List *)malloc(sizeof(List)); + + list_list->head = NULL; + list_list->length = 0; + list_list->tail = NULL; + + node_list->head = NULL; + node_list->length = 0; + node_list->tail = NULL; + if_safeMode = 1; } else{ @@ -71,11 +85,53 @@ int safeMode(int ifon){ return ifon; } +int releaseSingleList(List *p_list){ + Node *p_node = p_list->head; + List *plv_node = NULL; + while(p_node != NULL){ + plv_node = (List *)p_node->value; + plv_node->id = 0; + plv_node->head = NULL; + plv_node->length = 0; + plv_node->tail = NULL; + free(plv_node); + p_node = p_node->next; + } + p_list->head = NULL; + p_list->length = 0; + p_list->tail = NULL; + p_list->id = 0; + free(p_list); + return 0; +} + +int releaseSingleNode(List *p_list){ + Node *p_node = p_list->head; + Node *pnv_node = NULL; + while(p_node != NULL){ + pnv_node = (Node *)p_node->value; + pnv_node->id = 0; + pnv_node->if_setvalue = 0; + pnv_node->last = NULL; + pnv_node->next = NULL; + pnv_node->type = NULL; + pnv_node->value = NULL; + free(pnv_node); + p_node = p_node->next; + } + p_list->id = 0; + p_list->head = NULL; + p_list->length = 0; + p_list->tail = NULL; + free(p_list); + return 0; +} + int releaseAll(void){ if(if_safeMode == 1){ if_safeMode = 0; releaseList(node_list); - releaseList(list_list); + releaseSingleList(list_list); } return 0; } @@ -84,23 +140,35 @@ Node *init_node(void){ Node *p_node = (Node *) malloc(sizeof(Node)); p_node->id = getId(); p_node->if_setvalue = 0; - if(if_safeMode) insertInTail(node_list,p_node); + p_node->next = NULL; + p_node->last = NULL; + if(if_safeMode) { + if_safeMode = 0; + Node *prec_node = init_node(); + if_safeMode = 1; + init_value(prec_node, "pointer", (void *)p_node); + insertInTail(node_list,prec_node); + } return p_node; } List *init_list(void){ List *p_list = (List *) malloc(sizeof(List)); + p_list->id = getId(); p_list->head = NULL; p_list->tail = NULL; + p_list->length = 0; if(if_safeMode){ + if_safeMode = 0; Node *p_node = init_node(); - init_value(p_node,"pointer",(void *)p_list); + if_safeMode = 1; + init_value(p_node,"pointer",(void *)p_list); insertInTail(list_list,p_node); } return p_list; } -int init_value(Node *p_node,const char *type,void * p_value){ +int init_value(Node *p_node,const char *type,void *p_value){ p_node->if_setvalue = 1; p_node->type = type; p_node->value = p_value; @@ -161,10 +229,16 @@ int releaseNode(Node *p_node){ } p_node->last = NULL; p_node->next = NULL; + p_node->type = NULL; + p_node->value = NULL; + p_node->id = 0; + p_node->if_setvalue = 0; free(p_node); return 0; } + + int releaseList(List *p_list){ Node *p_node, *pl_node; p_node = p_list->head; @@ -182,6 +256,7 @@ int releaseList(List *p_list){ p_list->head = NULL; p_list->tail = NULL; p_list->length = 0; + p_list->id = 0; free(p_list); return 0; } @@ -198,7 +273,7 @@ int removeById(List *p_list, unsigned long id){ if(tmp->id == id) { tmp->last->next = tmp->next; tmp->next->last = tmp->last; - //releaseNode(tmp); not necessary + //releaseNode(tmp); 在安全模式下不必要 p_list->length -= 1; return 1;//found } @@ -218,7 +293,7 @@ int removeByNode(List *p_list, Node *p_node){ if(tmp == p_node){ tmp->last->next = tmp->next; tmp->next->last = tmp->last; - //releaseNode(tmp); not necessary + //releaseNode(tmp); 在安全模式下不必要 p_list->length -= 1; return 1;//found } @@ -266,9 +341,7 @@ int popFromTail(List *p_list){ return 0; } -/*The method in this function won't be better than going through the list - * node by node.The worst situation happens when the matched node is in - * the middle of the list.*/ +/*该函数算法需要改进*/ Node *findById(List *p_list, const unsigned long long id){ Node *ph_node = p_list->head; Node *pt_node = p_list->tail; @@ -295,6 +368,7 @@ Node *findById(List *p_list, const unsigned long long id){ return NULL; } + Node *findByValue(List *p_list, const char *type, const void *value){ Node *p_node = p_list->head; while(p_node != NULL){ diff --git a/list/list_easy.h b/ZE-Standard-Libraries/list/list_easy.h similarity index 100% rename from list/list_easy.h rename to ZE-Standard-Libraries/list/list_easy.h From f17d9f8f1eed5c25da9fc617461612de0d1d063f Mon Sep 17 00:00:00 2001 From: Saturneic Date: Sat, 9 Jun 2018 16:09:21 +0800 Subject: [PATCH 06/31] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E4=BA=86=E7=9B=AE?= =?UTF-8?q?=E5=BD=95=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- list/list.c | 32 ++++ list/list.h | 451 +++++++++++++++++++++++++++++++++++++++++++++++ list/list_easy.h | 72 ++++++++ 3 files changed, 555 insertions(+) create mode 100644 list/list.c create mode 100644 list/list.h create mode 100644 list/list_easy.h diff --git a/list/list.c b/list/list.c new file mode 100644 index 0000000..582fd0c --- /dev/null +++ b/list/list.c @@ -0,0 +1,32 @@ +/* ******************************************************** + * This file is used to test the header file(list.h). + * When the project is finished, this file will be deleted. + * This file create by saturneric at 20:04 on Feb 7th. + * *******************************************************/ + +#include "list.h" + +int main(int argc, char **argv){ + rand_init(); + safeMode(1); + List *t_list = init_list(); + + for(int i = 0; i < 9; i++){ + Node *t_node = init_node(); + int *t_i = (int *)malloc(sizeof(int)); + *t_i = i; + init_value(t_node,"int",(void *)t_i); + insertInTail(t_list,t_node); + } + + /*Node *t_node = init_node(); + insertInTail(t_list,t_node); + init_value(t_node,(void *)"there");*/ + + int *f_i = (int *)malloc(sizeof(int)); + *f_i = 3; + //releaseMalloc(); + releaseAll(); + + return 0; +} diff --git a/list/list.h b/list/list.h new file mode 100644 index 0000000..d4ed1f7 --- /dev/null +++ b/list/list.h @@ -0,0 +1,451 @@ +#include +#include +#include +#include + +#ifndef LIST_H +#define LIST_H + +typedef struct Node{ + unsigned long long id;//唯一标识符 + void *value; + int if_setvalue;//记录是否已经初始化值 + const char *type;//记录值的类型 + struct Node *next; + struct Node *last; +}Node; + + +typedef struct List{ + unsigned long long id;//唯一标识符 + Node *head; + Node *tail; + unsigned long long length;//链表长度 +}List; + +int safeMode(int ifon);//安全模式确保显式声明过的内存都会被释放 +int releaseMalloc(void);//释放所有声明过的内存 +int releaseSingleList(List *p_list); +int releaseSingleNode(List *p_list); +int releaseAll(void);//安全模式最后调用的函数 + +List *init_list(void); +Node *init_node(void); +int init_value(Node *,const char *,void *); +void init_rand(void); + +unsigned long long getId(void); + +int insertInHead(List *p_list, Node *p_node); +int insertInTail(List *p_list, Node *p_node); + +int removeById(List *p_list, unsigned long id); +int removeByNode(List *p_list, Node *p_node); + +int popFromHead(List *p_list); +int popFromTail(List *p_list); + +unsigned long long len(List *p_list); + +Node *findById(List *p_list, const unsigned long long id); +Node *findByValue(List *p_list, const char *type, const void *value); +List *mply_findByValue(List *p_list, const char *type, const void *value);//寻找多个值匹配的节点 + +int releaseList(List *p_list); +int releaseNode(Node *p_node); + +int isListEmpty(List *p_list); + +/*有关安全模式的变量*/ +int if_safeMode = 0; +List *node_list = NULL; //储存声明过的节点. +List *list_list = NULL; //储存声明过的链表. + +int safeMode(int ifon){ + if(ifon == 1){ + if (node_list == NULL && list_list == NULL){ + node_list = (List *)malloc(sizeof(List)); + list_list = (List *)malloc(sizeof(List)); + + list_list->head = NULL; + list_list->length = 0; + list_list->tail = NULL; + + node_list->head = NULL; + node_list->length = 0; + node_list->tail = NULL; + + if_safeMode = 1; + } + else{ + return -1; + } + } + + return ifon; +} + +int releaseSingleList(List *p_list){ + Node *p_node = p_list->head; + List *plv_node = NULL; + while(p_node != NULL){ + plv_node = (List *)p_node->value; + plv_node->id = 0; + plv_node->head = NULL; + plv_node->length = 0; + plv_node->tail = NULL; + free(plv_node); + p_node = p_node->next; + } + p_list->head = NULL; + p_list->length = 0; + p_list->tail = NULL; + p_list->id = 0; + free(p_list); + return 0; +} + +int releaseSingleNode(List *p_list){ + Node *p_node = p_list->head; + Node *pnv_node = NULL; + while(p_node != NULL){ + pnv_node = (Node *)p_node->value; + pnv_node->id = 0; + pnv_node->if_setvalue = 0; + pnv_node->last = NULL; + pnv_node->next = NULL; + pnv_node->type = NULL; + pnv_node->value = NULL; + free(pnv_node); + p_node = p_node->next; + } + p_list->id = 0; + p_list->head = NULL; + p_list->length = 0; + p_list->tail = NULL; + free(p_list); + return 0; +} + +int releaseAll(void){ + if(if_safeMode == 1){ + if_safeMode = 0; + releaseList(node_list); + releaseSingleList(list_list); + } + return 0; +} + +Node *init_node(void){ + Node *p_node = (Node *) malloc(sizeof(Node)); + p_node->id = getId(); + p_node->if_setvalue = 0; + p_node->next = NULL; + p_node->last = NULL; + if(if_safeMode) { + if_safeMode = 0; + Node *prec_node = init_node(); + if_safeMode = 1; + init_value(prec_node, "pointer", (void *)p_node); + insertInTail(node_list,prec_node); + } + return p_node; +} + +List *init_list(void){ + List *p_list = (List *) malloc(sizeof(List)); + p_list->id = getId(); + p_list->head = NULL; + p_list->tail = NULL; + p_list->length = 0; + if(if_safeMode){ + if_safeMode = 0; + Node *p_node = init_node(); + if_safeMode = 1; + init_value(p_node,"pointer",(void *)p_list); + insertInTail(list_list,p_node); + } + return p_list; +} + +int init_value(Node *p_node,const char *type,void *p_value){ + p_node->if_setvalue = 1; + p_node->type = type; + p_node->value = p_value; + return 0; +} + +void rand_init(void){ + srandom((unsigned)time(NULL)); +} + +unsigned long long getId(void){ + unsigned long long id = 0; + id = ((random()%9)+1); + for(int i = 0; i < 15; i++){ + id *= 10; + id += random()%10; + } + return id; +} + +int insertInHead(List *p_list, Node *p_node){ + if( isListEmpty(p_list) ){ + p_list->head = p_node; + p_list->tail = p_node; + } + else{ + p_list->head->last = p_node; + p_node->last = NULL; + p_node->next = p_list->head; + p_list->head = p_node; + } + p_list->length += 1; + return 0; +} + +int insertInTail(List *p_list, Node *p_node){ + if( isListEmpty(p_list) ){ + p_list->head = p_node; + p_list->tail = p_node; + } + else{ + p_list->tail->next = p_node; + p_node->next = NULL; + p_node->last = p_list->tail; + p_list->tail = p_node; + } + p_list->length += 1; + return 0; +} + +int releaseNode(Node *p_node){ + if(if_safeMode == 1){ + removeByNode(node_list,p_node); + } + if(p_node->if_setvalue == 1){ + free(p_node->value); + p_node->value = NULL; + } + p_node->last = NULL; + p_node->next = NULL; + p_node->type = NULL; + p_node->value = NULL; + p_node->id = 0; + p_node->if_setvalue = 0; + free(p_node); + return 0; +} + + + +int releaseList(List *p_list){ + Node *p_node, *pl_node; + p_node = p_list->head; + if(if_safeMode == 1){ + Node *tar_list = findByValue(list_list,"pointer",(void *)p_list);//turn pointer in to int to compare. + removeByNode(list_list,tar_list); + } + while (p_node != NULL){ + pl_node = p_node; + p_node = p_node->next; + pl_node->next = NULL; + pl_node->last = NULL; + releaseNode(pl_node); + } + p_list->head = NULL; + p_list->tail = NULL; + p_list->length = 0; + p_list->id = 0; + free(p_list); + return 0; +} + +unsigned long long len(List *p_list){ + return p_list->length; +} + +int removeById(List *p_list, unsigned long id){ + Node *tmp = p_list->head; + if( isListEmpty(p_list) ) + return -1; + do{ + if(tmp->id == id) { + tmp->last->next = tmp->next; + tmp->next->last = tmp->last; + //releaseNode(tmp); 在安全模式下不必要 + p_list->length -= 1; + return 1;//found + } + else{ + tmp = tmp->next; + } + }while(tmp != NULL); + + return 0;//not find +} + +int removeByNode(List *p_list, Node *p_node){ + Node *tmp = p_list->head; + if( isListEmpty(p_list) ) + return -1; + do{ + if(tmp == p_node){ + tmp->last->next = tmp->next; + tmp->next->last = tmp->last; + //releaseNode(tmp); 在安全模式下不必要 + p_list->length -= 1; + return 1;//found + } + else{ + tmp = tmp->next; + } + }while(tmp != NULL); + + return 0;//not find +} + +int popFromHead(List *p_list){ + if( isListEmpty(p_list) ) + return -1; + else{ + //Node *tmp = p_list->head; + p_list->head->next->last = NULL; + p_list->head = p_list->head->next; + //releaseNode(tmp); not necessary + p_list->length -= 1; + } + + if( isListEmpty(p_list) ){ + p_list->head = NULL; + p_list->tail = NULL; + } + return 0; +} + +int popFromTail(List *p_list){ + if( isListEmpty(p_list) ) + return -1; + else{ + //Node *tmp = p_list->tail; + p_list->tail->last->next = NULL; + p_list->tail = p_list->tail->last; + //releaseNode(tmp); not necessary + p_list->length -= 1; + } + + if( isListEmpty(p_list) ){ + p_list->head = NULL; + p_list->tail = NULL; + } + return 0; +} + +/*该函数算法需要改进*/ +Node *findById(List *p_list, const unsigned long long id){ + Node *ph_node = p_list->head; + Node *pt_node = p_list->tail; + int direction = 0; + while(ph_node != pt_node){ + if (direction == 0){ + if (ph_node->id == id){ + return ph_node; + } + else{ + ph_node = ph_node->next; + } + direction = 1; + } + else{ + if (pt_node->id == id){ + return pt_node; + } + else{ + pt_node = pt_node->last; + } + } + } + return NULL; +} + + +Node *findByValue(List *p_list, const char *type, const void *value){ + Node *p_node = p_list->head; + while(p_node != NULL){ + if(strcmp(p_node->type,type)) continue;//continue when type is not the same. + if(!strcmp(type,"int")){ + if(*((int *)p_node->value) == *((int *)value)){ + return p_node; + } + } + else if(!strcmp(type,"double")){ + if(*((double *)p_node->value) == *((double *)value)){ + return p_node; + } + } + else if(!strcmp (type,"string")){ + if(!strcmp((char *)p_node->value,(char *)value)) + { + return p_node; + } + } + else if(!strcmp(type,"pointer")){ + if(p_node->value == value){ + return p_node; + } + } + + p_node = p_node->next; + + } + return NULL; +} + +List *mply_findByValue(List *p_list, const char *type, const void *value){ + List *f_list = init_list(); + Node *p_node = p_list->head; + while(p_node != NULL){ + if(strcmp(p_node->type,type)) continue; + if(!strcmp(type,"int")){ + if(*((int *)p_node->value) == *((int *)value)){ + Node *f_node = init_node(); + init_value(f_node,"pointer",(void *)p_node); + insertInTail(f_list,f_node); + } + } + else if(!strcmp(type,"double")){ + if(*((double *)p_node->value) == *((double *)value)){ + Node *f_node = init_node(); + init_value(f_node,"pointer",(void *)p_node); + insertInTail(f_list,f_node); + } + } + else if(!strcmp (type,"string")){ + if(!strcmp((char *)p_node->value,(char *)value)) + { + Node *f_node = init_node(); + init_value(f_node,"pointer",(void *)p_node); + insertInTail(f_list,f_node); + } + } + else if(!strcmp(type,"pointer")){ + if(p_node->value == value){ + Node *f_node = init_node(); + init_value(f_node,"pointer",(void *)p_node); + insertInTail(f_list,f_node); + } + } + + p_node = p_node->next; + + } + return f_list; +} + +int isListEmpty(List *p_list){ + if(p_list->head == NULL || p_list->tail == NULL)// If its head or tail is NULL,it would be thought as empty. + return 1; // But we should ensure that both of them are NULL when we + return 0; // want to make a list empty. +} + +#endif diff --git a/list/list_easy.h b/list/list_easy.h new file mode 100644 index 0000000..e35c68e --- /dev/null +++ b/list/list_easy.h @@ -0,0 +1,72 @@ +#include "list.h" + +#ifndef LIST_EASY_H +#define LIST_EASY_H + +Node *new_nodeWithInt(int); +Node *new_nodeWithDouble(double); +Node *new_nodeWithString(const char *); +Node *new_nodeWithPointer(void *); +Node *find_nodeByIndex(List *, unsigned long long); +int list_through(List *p_list, int (*p_func)(void *, const char *));//Go through the list.Call p_func every time. + + +Node *new_nodeWithInt(int m_int){ + int *p_int = (int *)malloc(sizeof(int)); + *p_int = m_int; + Node *p_node = init_node(); + init_value(p_node,"int",(void *)p_int); + return p_node; +} + +Node *new_nodeWithDouble(double m_double){ + double *p_double = (double *)malloc(sizeof(double)); + *p_double = m_double; + Node *p_node = init_node(); + init_value(p_node,"double",(void *)p_double); + return p_node; +} + +Node *new_nodeWithString(const char *m_string){ + char *p_string = (char *)malloc(sizeof(char)*(strlen(m_string)+1)); + strcpy(p_string,m_string); + Node *p_node = init_node(); + init_value(p_node,"string",(void *)p_string); + return p_node; +} + +Node *new_nodeWithPointer(void *m_pointer){ + Node *p_node = init_node(); + init_value(p_node,"pointer",(void *)m_pointer); + return p_node; +} + +Node *find_nodeByIndex(List *p_list, unsigned long long m_index){ + Node *p_node = p_list->head; + for(unsigned long long i= 0; i < m_index; i++){ + p_node = p_node->next; + } + return p_node; +} + +int list_through(List *p_list, int (*p_func)(void *, const char *)){ + Node *p_node = p_list->head; + while(p_node != NULL){ + if(p_node->if_setvalue == 1){ + int m_return = (*p_func)(p_node->value, p_node->type); + if (m_return == -1) break; + else if (m_return == 1){ + p_node = p_node->last; + continue; + } + else{ + + } + } + p_node = p_node->next; + } + return 0; +} + + +#endif From efc7bfe9b22d09b6fa87c80923e17034afe3098f Mon Sep 17 00:00:00 2001 From: Saturneic Date: Sat, 9 Jun 2018 16:25:07 +0800 Subject: [PATCH 07/31] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E4=BA=86=E7=9B=AE?= =?UTF-8?q?=E5=BD=95=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ZE-Standard-Libraries/list/list.c | 32 -- ZE-Standard-Libraries/list/list.h | 451 ------------------------- ZE-Standard-Libraries/list/list_easy.h | 72 ---- 3 files changed, 555 deletions(-) delete mode 100644 ZE-Standard-Libraries/list/list.c delete mode 100644 ZE-Standard-Libraries/list/list.h delete mode 100644 ZE-Standard-Libraries/list/list_easy.h diff --git a/ZE-Standard-Libraries/list/list.c b/ZE-Standard-Libraries/list/list.c deleted file mode 100644 index 582fd0c..0000000 --- a/ZE-Standard-Libraries/list/list.c +++ /dev/null @@ -1,32 +0,0 @@ -/* ******************************************************** - * This file is used to test the header file(list.h). - * When the project is finished, this file will be deleted. - * This file create by saturneric at 20:04 on Feb 7th. - * *******************************************************/ - -#include "list.h" - -int main(int argc, char **argv){ - rand_init(); - safeMode(1); - List *t_list = init_list(); - - for(int i = 0; i < 9; i++){ - Node *t_node = init_node(); - int *t_i = (int *)malloc(sizeof(int)); - *t_i = i; - init_value(t_node,"int",(void *)t_i); - insertInTail(t_list,t_node); - } - - /*Node *t_node = init_node(); - insertInTail(t_list,t_node); - init_value(t_node,(void *)"there");*/ - - int *f_i = (int *)malloc(sizeof(int)); - *f_i = 3; - //releaseMalloc(); - releaseAll(); - - return 0; -} diff --git a/ZE-Standard-Libraries/list/list.h b/ZE-Standard-Libraries/list/list.h deleted file mode 100644 index d4ed1f7..0000000 --- a/ZE-Standard-Libraries/list/list.h +++ /dev/null @@ -1,451 +0,0 @@ -#include -#include -#include -#include - -#ifndef LIST_H -#define LIST_H - -typedef struct Node{ - unsigned long long id;//唯一标识符 - void *value; - int if_setvalue;//记录是否已经初始化值 - const char *type;//记录值的类型 - struct Node *next; - struct Node *last; -}Node; - - -typedef struct List{ - unsigned long long id;//唯一标识符 - Node *head; - Node *tail; - unsigned long long length;//链表长度 -}List; - -int safeMode(int ifon);//安全模式确保显式声明过的内存都会被释放 -int releaseMalloc(void);//释放所有声明过的内存 -int releaseSingleList(List *p_list); -int releaseSingleNode(List *p_list); -int releaseAll(void);//安全模式最后调用的函数 - -List *init_list(void); -Node *init_node(void); -int init_value(Node *,const char *,void *); -void init_rand(void); - -unsigned long long getId(void); - -int insertInHead(List *p_list, Node *p_node); -int insertInTail(List *p_list, Node *p_node); - -int removeById(List *p_list, unsigned long id); -int removeByNode(List *p_list, Node *p_node); - -int popFromHead(List *p_list); -int popFromTail(List *p_list); - -unsigned long long len(List *p_list); - -Node *findById(List *p_list, const unsigned long long id); -Node *findByValue(List *p_list, const char *type, const void *value); -List *mply_findByValue(List *p_list, const char *type, const void *value);//寻找多个值匹配的节点 - -int releaseList(List *p_list); -int releaseNode(Node *p_node); - -int isListEmpty(List *p_list); - -/*有关安全模式的变量*/ -int if_safeMode = 0; -List *node_list = NULL; //储存声明过的节点. -List *list_list = NULL; //储存声明过的链表. - -int safeMode(int ifon){ - if(ifon == 1){ - if (node_list == NULL && list_list == NULL){ - node_list = (List *)malloc(sizeof(List)); - list_list = (List *)malloc(sizeof(List)); - - list_list->head = NULL; - list_list->length = 0; - list_list->tail = NULL; - - node_list->head = NULL; - node_list->length = 0; - node_list->tail = NULL; - - if_safeMode = 1; - } - else{ - return -1; - } - } - - return ifon; -} - -int releaseSingleList(List *p_list){ - Node *p_node = p_list->head; - List *plv_node = NULL; - while(p_node != NULL){ - plv_node = (List *)p_node->value; - plv_node->id = 0; - plv_node->head = NULL; - plv_node->length = 0; - plv_node->tail = NULL; - free(plv_node); - p_node = p_node->next; - } - p_list->head = NULL; - p_list->length = 0; - p_list->tail = NULL; - p_list->id = 0; - free(p_list); - return 0; -} - -int releaseSingleNode(List *p_list){ - Node *p_node = p_list->head; - Node *pnv_node = NULL; - while(p_node != NULL){ - pnv_node = (Node *)p_node->value; - pnv_node->id = 0; - pnv_node->if_setvalue = 0; - pnv_node->last = NULL; - pnv_node->next = NULL; - pnv_node->type = NULL; - pnv_node->value = NULL; - free(pnv_node); - p_node = p_node->next; - } - p_list->id = 0; - p_list->head = NULL; - p_list->length = 0; - p_list->tail = NULL; - free(p_list); - return 0; -} - -int releaseAll(void){ - if(if_safeMode == 1){ - if_safeMode = 0; - releaseList(node_list); - releaseSingleList(list_list); - } - return 0; -} - -Node *init_node(void){ - Node *p_node = (Node *) malloc(sizeof(Node)); - p_node->id = getId(); - p_node->if_setvalue = 0; - p_node->next = NULL; - p_node->last = NULL; - if(if_safeMode) { - if_safeMode = 0; - Node *prec_node = init_node(); - if_safeMode = 1; - init_value(prec_node, "pointer", (void *)p_node); - insertInTail(node_list,prec_node); - } - return p_node; -} - -List *init_list(void){ - List *p_list = (List *) malloc(sizeof(List)); - p_list->id = getId(); - p_list->head = NULL; - p_list->tail = NULL; - p_list->length = 0; - if(if_safeMode){ - if_safeMode = 0; - Node *p_node = init_node(); - if_safeMode = 1; - init_value(p_node,"pointer",(void *)p_list); - insertInTail(list_list,p_node); - } - return p_list; -} - -int init_value(Node *p_node,const char *type,void *p_value){ - p_node->if_setvalue = 1; - p_node->type = type; - p_node->value = p_value; - return 0; -} - -void rand_init(void){ - srandom((unsigned)time(NULL)); -} - -unsigned long long getId(void){ - unsigned long long id = 0; - id = ((random()%9)+1); - for(int i = 0; i < 15; i++){ - id *= 10; - id += random()%10; - } - return id; -} - -int insertInHead(List *p_list, Node *p_node){ - if( isListEmpty(p_list) ){ - p_list->head = p_node; - p_list->tail = p_node; - } - else{ - p_list->head->last = p_node; - p_node->last = NULL; - p_node->next = p_list->head; - p_list->head = p_node; - } - p_list->length += 1; - return 0; -} - -int insertInTail(List *p_list, Node *p_node){ - if( isListEmpty(p_list) ){ - p_list->head = p_node; - p_list->tail = p_node; - } - else{ - p_list->tail->next = p_node; - p_node->next = NULL; - p_node->last = p_list->tail; - p_list->tail = p_node; - } - p_list->length += 1; - return 0; -} - -int releaseNode(Node *p_node){ - if(if_safeMode == 1){ - removeByNode(node_list,p_node); - } - if(p_node->if_setvalue == 1){ - free(p_node->value); - p_node->value = NULL; - } - p_node->last = NULL; - p_node->next = NULL; - p_node->type = NULL; - p_node->value = NULL; - p_node->id = 0; - p_node->if_setvalue = 0; - free(p_node); - return 0; -} - - - -int releaseList(List *p_list){ - Node *p_node, *pl_node; - p_node = p_list->head; - if(if_safeMode == 1){ - Node *tar_list = findByValue(list_list,"pointer",(void *)p_list);//turn pointer in to int to compare. - removeByNode(list_list,tar_list); - } - while (p_node != NULL){ - pl_node = p_node; - p_node = p_node->next; - pl_node->next = NULL; - pl_node->last = NULL; - releaseNode(pl_node); - } - p_list->head = NULL; - p_list->tail = NULL; - p_list->length = 0; - p_list->id = 0; - free(p_list); - return 0; -} - -unsigned long long len(List *p_list){ - return p_list->length; -} - -int removeById(List *p_list, unsigned long id){ - Node *tmp = p_list->head; - if( isListEmpty(p_list) ) - return -1; - do{ - if(tmp->id == id) { - tmp->last->next = tmp->next; - tmp->next->last = tmp->last; - //releaseNode(tmp); 在安全模式下不必要 - p_list->length -= 1; - return 1;//found - } - else{ - tmp = tmp->next; - } - }while(tmp != NULL); - - return 0;//not find -} - -int removeByNode(List *p_list, Node *p_node){ - Node *tmp = p_list->head; - if( isListEmpty(p_list) ) - return -1; - do{ - if(tmp == p_node){ - tmp->last->next = tmp->next; - tmp->next->last = tmp->last; - //releaseNode(tmp); 在安全模式下不必要 - p_list->length -= 1; - return 1;//found - } - else{ - tmp = tmp->next; - } - }while(tmp != NULL); - - return 0;//not find -} - -int popFromHead(List *p_list){ - if( isListEmpty(p_list) ) - return -1; - else{ - //Node *tmp = p_list->head; - p_list->head->next->last = NULL; - p_list->head = p_list->head->next; - //releaseNode(tmp); not necessary - p_list->length -= 1; - } - - if( isListEmpty(p_list) ){ - p_list->head = NULL; - p_list->tail = NULL; - } - return 0; -} - -int popFromTail(List *p_list){ - if( isListEmpty(p_list) ) - return -1; - else{ - //Node *tmp = p_list->tail; - p_list->tail->last->next = NULL; - p_list->tail = p_list->tail->last; - //releaseNode(tmp); not necessary - p_list->length -= 1; - } - - if( isListEmpty(p_list) ){ - p_list->head = NULL; - p_list->tail = NULL; - } - return 0; -} - -/*该函数算法需要改进*/ -Node *findById(List *p_list, const unsigned long long id){ - Node *ph_node = p_list->head; - Node *pt_node = p_list->tail; - int direction = 0; - while(ph_node != pt_node){ - if (direction == 0){ - if (ph_node->id == id){ - return ph_node; - } - else{ - ph_node = ph_node->next; - } - direction = 1; - } - else{ - if (pt_node->id == id){ - return pt_node; - } - else{ - pt_node = pt_node->last; - } - } - } - return NULL; -} - - -Node *findByValue(List *p_list, const char *type, const void *value){ - Node *p_node = p_list->head; - while(p_node != NULL){ - if(strcmp(p_node->type,type)) continue;//continue when type is not the same. - if(!strcmp(type,"int")){ - if(*((int *)p_node->value) == *((int *)value)){ - return p_node; - } - } - else if(!strcmp(type,"double")){ - if(*((double *)p_node->value) == *((double *)value)){ - return p_node; - } - } - else if(!strcmp (type,"string")){ - if(!strcmp((char *)p_node->value,(char *)value)) - { - return p_node; - } - } - else if(!strcmp(type,"pointer")){ - if(p_node->value == value){ - return p_node; - } - } - - p_node = p_node->next; - - } - return NULL; -} - -List *mply_findByValue(List *p_list, const char *type, const void *value){ - List *f_list = init_list(); - Node *p_node = p_list->head; - while(p_node != NULL){ - if(strcmp(p_node->type,type)) continue; - if(!strcmp(type,"int")){ - if(*((int *)p_node->value) == *((int *)value)){ - Node *f_node = init_node(); - init_value(f_node,"pointer",(void *)p_node); - insertInTail(f_list,f_node); - } - } - else if(!strcmp(type,"double")){ - if(*((double *)p_node->value) == *((double *)value)){ - Node *f_node = init_node(); - init_value(f_node,"pointer",(void *)p_node); - insertInTail(f_list,f_node); - } - } - else if(!strcmp (type,"string")){ - if(!strcmp((char *)p_node->value,(char *)value)) - { - Node *f_node = init_node(); - init_value(f_node,"pointer",(void *)p_node); - insertInTail(f_list,f_node); - } - } - else if(!strcmp(type,"pointer")){ - if(p_node->value == value){ - Node *f_node = init_node(); - init_value(f_node,"pointer",(void *)p_node); - insertInTail(f_list,f_node); - } - } - - p_node = p_node->next; - - } - return f_list; -} - -int isListEmpty(List *p_list){ - if(p_list->head == NULL || p_list->tail == NULL)// If its head or tail is NULL,it would be thought as empty. - return 1; // But we should ensure that both of them are NULL when we - return 0; // want to make a list empty. -} - -#endif diff --git a/ZE-Standard-Libraries/list/list_easy.h b/ZE-Standard-Libraries/list/list_easy.h deleted file mode 100644 index e35c68e..0000000 --- a/ZE-Standard-Libraries/list/list_easy.h +++ /dev/null @@ -1,72 +0,0 @@ -#include "list.h" - -#ifndef LIST_EASY_H -#define LIST_EASY_H - -Node *new_nodeWithInt(int); -Node *new_nodeWithDouble(double); -Node *new_nodeWithString(const char *); -Node *new_nodeWithPointer(void *); -Node *find_nodeByIndex(List *, unsigned long long); -int list_through(List *p_list, int (*p_func)(void *, const char *));//Go through the list.Call p_func every time. - - -Node *new_nodeWithInt(int m_int){ - int *p_int = (int *)malloc(sizeof(int)); - *p_int = m_int; - Node *p_node = init_node(); - init_value(p_node,"int",(void *)p_int); - return p_node; -} - -Node *new_nodeWithDouble(double m_double){ - double *p_double = (double *)malloc(sizeof(double)); - *p_double = m_double; - Node *p_node = init_node(); - init_value(p_node,"double",(void *)p_double); - return p_node; -} - -Node *new_nodeWithString(const char *m_string){ - char *p_string = (char *)malloc(sizeof(char)*(strlen(m_string)+1)); - strcpy(p_string,m_string); - Node *p_node = init_node(); - init_value(p_node,"string",(void *)p_string); - return p_node; -} - -Node *new_nodeWithPointer(void *m_pointer){ - Node *p_node = init_node(); - init_value(p_node,"pointer",(void *)m_pointer); - return p_node; -} - -Node *find_nodeByIndex(List *p_list, unsigned long long m_index){ - Node *p_node = p_list->head; - for(unsigned long long i= 0; i < m_index; i++){ - p_node = p_node->next; - } - return p_node; -} - -int list_through(List *p_list, int (*p_func)(void *, const char *)){ - Node *p_node = p_list->head; - while(p_node != NULL){ - if(p_node->if_setvalue == 1){ - int m_return = (*p_func)(p_node->value, p_node->type); - if (m_return == -1) break; - else if (m_return == 1){ - p_node = p_node->last; - continue; - } - else{ - - } - } - p_node = p_node->next; - } - return 0; -} - - -#endif From 684a842b7e2c5dfc91d952f4e73b6dbe5594041f Mon Sep 17 00:00:00 2001 From: Saturneic Date: Sun, 10 Jun 2018 17:21:11 +0800 Subject: [PATCH 08/31] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E4=BA=86=E4=B8=80?= =?UTF-8?q?=E4=BA=9B=E7=AE=80=E4=BE=BF=E3=80=82=E5=B9=B6=E4=B8=94=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0=E4=BA=86=E7=AC=A6=E5=90=88=E5=80=BC=E8=8A=82=E7=82=B9?= =?UTF-8?q?=E7=9A=84=E5=AE=9A=E4=B9=89=E5=8F=8A=E4=B8=80=E4=BA=9B=E5=8A=9F?= =?UTF-8?q?=E8=83=BD=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- list/list.c | 32 +++-- list/list.h | 89 ++++++++------ list/list_easy.h | 72 ----------- list/list_expand.h | 298 +++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 374 insertions(+), 117 deletions(-) delete mode 100644 list/list_easy.h create mode 100644 list/list_expand.h diff --git a/list/list.c b/list/list.c index 582fd0c..9bcf50f 100644 --- a/list/list.c +++ b/list/list.c @@ -5,28 +5,40 @@ * *******************************************************/ #include "list.h" +#include "list_expand.h" int main(int argc, char **argv){ rand_init(); - safeMode(1); List *t_list = init_list(); - for(int i = 0; i < 9; i++){ + /*for(int i = 0; i < 9; i++){ Node *t_node = init_node(); int *t_i = (int *)malloc(sizeof(int)); *t_i = i; - init_value(t_node,"int",(void *)t_i); + initMallocValue(t_node,"int",(void *)t_i); insertInTail(t_list,t_node); - } + }*/ /*Node *t_node = init_node(); insertInTail(t_list,t_node); - init_value(t_node,(void *)"there");*/ - - int *f_i = (int *)malloc(sizeof(int)); - *f_i = 3; - //releaseMalloc(); - releaseAll(); + initMalllocValue(t_node,(void *)"there");*/ + + for(int i = 0; i < 12; i++){ + insertInHead(t_list, nodeWithInt(i)); + } + + + Node *t_node = nodeWithComplex(); + addIntForComplex(t_node, 32); + addIntForComplex(t_node, 64); + insertInTail(t_list, t_node); + insertInTail(t_list, nodeWithDouble(32.5)); + insertInTail(t_list, nodeWithString("There")); + printNodeInfo(findByString(t_list, "There"), 0); + printListInfo(t_list,0); + printList(t_list); + printf("\n"); + releaseList(t_list); return 0; } diff --git a/list/list.h b/list/list.h index d4ed1f7..9c74c6d 100644 --- a/list/list.h +++ b/list/list.h @@ -9,7 +9,7 @@ typedef struct Node{ unsigned long long id;//唯一标识符 void *value; - int if_setvalue;//记录是否已经初始化值 + int if_malloc;//记录是否已经初始化值 const char *type;//记录值的类型 struct Node *next; struct Node *last; @@ -24,37 +24,40 @@ typedef struct List{ }List; int safeMode(int ifon);//安全模式确保显式声明过的内存都会被释放 -int releaseMalloc(void);//释放所有声明过的内存 -int releaseSingleList(List *p_list); -int releaseSingleNode(List *p_list); +int releaseSingleListForSafeMode(List *p_list);//释放list_list +int releaseSingleNodeForSafeMode(List *p_list);//释放node_list int releaseAll(void);//安全模式最后调用的函数 List *init_list(void); Node *init_node(void); -int init_value(Node *,const char *,void *); -void init_rand(void); +int initMallocValue(Node *,const char *,void *);//赋予已分配内存的值,并标明类型 + +/*有关id的函数*/ +void init_rand(void); unsigned long long getId(void); +/*插入函数*/ int insertInHead(List *p_list, Node *p_node); int insertInTail(List *p_list, Node *p_node); +/*移除函数*/ int removeById(List *p_list, unsigned long id); int removeByNode(List *p_list, Node *p_node); - int popFromHead(List *p_list); int popFromTail(List *p_list); -unsigned long long len(List *p_list); +unsigned long long len(List *p_list);//查看链表的长度 -Node *findById(List *p_list, const unsigned long long id); -Node *findByValue(List *p_list, const char *type, const void *value); +Node *findById(List *p_list, const unsigned long long id);//通过id查找目标链表中的匹配节点 +Node *findByValue(List *p_list, const char *type, const void *value);//通过值来查找目标链表中的匹配节点 List *mply_findByValue(List *p_list, const char *type, const void *value);//寻找多个值匹配的节点 -int releaseList(List *p_list); -int releaseNode(Node *p_node); +int releaseList(List *p_list);//释放List并可选择是否释放中所有的其中的Node +int releaseListForSingle(List *p_list);//单独释放List +int releaseNode(Node *p_node);//释放Node -int isListEmpty(List *p_list); +int isListEmpty(List *p_list);//判断List是否为空 /*有关安全模式的变量*/ int if_safeMode = 0; @@ -85,7 +88,7 @@ int safeMode(int ifon){ return ifon; } -int releaseSingleList(List *p_list){ +int releaseSingleListForSafeMode(List *p_list){ Node *p_node = p_list->head; List *plv_node = NULL; while(p_node != NULL){ @@ -105,13 +108,13 @@ int releaseSingleList(List *p_list){ return 0; } -int releaseSingleNode(List *p_list){ +int releaseSingleNodeForSafeMode(List *p_list){ Node *p_node = p_list->head; Node *pnv_node = NULL; while(p_node != NULL){ pnv_node = (Node *)p_node->value; pnv_node->id = 0; - pnv_node->if_setvalue = 0; + pnv_node->if_malloc = 0; pnv_node->last = NULL; pnv_node->next = NULL; pnv_node->type = NULL; @@ -130,8 +133,8 @@ int releaseSingleNode(List *p_list){ int releaseAll(void){ if(if_safeMode == 1){ if_safeMode = 0; - releaseList(node_list); - releaseSingleList(list_list); + releaseSingleNodeForSafeMode(node_list); + releaseSingleListForSafeMode(list_list); } return 0; } @@ -139,14 +142,14 @@ int releaseAll(void){ Node *init_node(void){ Node *p_node = (Node *) malloc(sizeof(Node)); p_node->id = getId(); - p_node->if_setvalue = 0; + p_node->if_malloc = 0; p_node->next = NULL; p_node->last = NULL; if(if_safeMode) { if_safeMode = 0; Node *prec_node = init_node(); if_safeMode = 1; - init_value(prec_node, "pointer", (void *)p_node); + initMallocValue(prec_node, "pointer", (void *)p_node); insertInTail(node_list,prec_node); } return p_node; @@ -162,14 +165,14 @@ List *init_list(void){ if_safeMode = 0; Node *p_node = init_node(); if_safeMode = 1; - init_value(p_node,"pointer",(void *)p_list); + initMallocValue(p_node,"pointer",(void *)p_list); insertInTail(list_list,p_node); } return p_list; } -int init_value(Node *p_node,const char *type,void *p_value){ - p_node->if_setvalue = 1; +int initMallocValue(Node *p_node,const char *type,void *p_value){ + p_node->if_malloc = 1; p_node->type = type; p_node->value = p_value; return 0; @@ -223,22 +226,28 @@ int releaseNode(Node *p_node){ if(if_safeMode == 1){ removeByNode(node_list,p_node); } - if(p_node->if_setvalue == 1){ - free(p_node->value); - p_node->value = NULL; + if(p_node->if_malloc == 1){ + if(strcmp(p_node->type,"pointer")) { + if(!strcmp(p_node->type, "list")){ + releaseList((List *)p_node->value); + } + else{ + free(p_node->value); + } + } + p_node->value = NULL; } p_node->last = NULL; p_node->next = NULL; p_node->type = NULL; p_node->value = NULL; p_node->id = 0; - p_node->if_setvalue = 0; + p_node->if_malloc = 0; free(p_node); return 0; } - int releaseList(List *p_list){ Node *p_node, *pl_node; p_node = p_list->head; @@ -261,6 +270,15 @@ int releaseList(List *p_list){ return 0; } +int releaseListForSingle(List *p_list){ + p_list->head = NULL; + p_list->tail = NULL; + p_list->id = 0; + p_list->length = 0; + free(p_list); + return 0; +} + unsigned long long len(List *p_list){ return p_list->length; } @@ -273,7 +291,6 @@ int removeById(List *p_list, unsigned long id){ if(tmp->id == id) { tmp->last->next = tmp->next; tmp->next->last = tmp->last; - //releaseNode(tmp); 在安全模式下不必要 p_list->length -= 1; return 1;//found } @@ -293,7 +310,6 @@ int removeByNode(List *p_list, Node *p_node){ if(tmp == p_node){ tmp->last->next = tmp->next; tmp->next->last = tmp->last; - //releaseNode(tmp); 在安全模式下不必要 p_list->length -= 1; return 1;//found } @@ -372,7 +388,10 @@ Node *findById(List *p_list, const unsigned long long id){ Node *findByValue(List *p_list, const char *type, const void *value){ Node *p_node = p_list->head; while(p_node != NULL){ - if(strcmp(p_node->type,type)) continue;//continue when type is not the same. + if(strcmp(p_node->type,type)){ + p_node = p_node->next; + continue;//跳过不合类型的节点 + } if(!strcmp(type,"int")){ if(*((int *)p_node->value) == *((int *)value)){ return p_node; @@ -409,14 +428,14 @@ List *mply_findByValue(List *p_list, const char *type, const void *value){ if(!strcmp(type,"int")){ if(*((int *)p_node->value) == *((int *)value)){ Node *f_node = init_node(); - init_value(f_node,"pointer",(void *)p_node); + initMallocValue(f_node,"pointer",(void *)p_node); insertInTail(f_list,f_node); } } else if(!strcmp(type,"double")){ if(*((double *)p_node->value) == *((double *)value)){ Node *f_node = init_node(); - init_value(f_node,"pointer",(void *)p_node); + initMallocValue(f_node,"pointer",(void *)p_node); insertInTail(f_list,f_node); } } @@ -424,14 +443,14 @@ List *mply_findByValue(List *p_list, const char *type, const void *value){ if(!strcmp((char *)p_node->value,(char *)value)) { Node *f_node = init_node(); - init_value(f_node,"pointer",(void *)p_node); + initMallocValue(f_node,"pointer",(void *)p_node); insertInTail(f_list,f_node); } } else if(!strcmp(type,"pointer")){ if(p_node->value == value){ Node *f_node = init_node(); - init_value(f_node,"pointer",(void *)p_node); + initMallocValue(f_node,"pointer",(void *)p_node); insertInTail(f_list,f_node); } } diff --git a/list/list_easy.h b/list/list_easy.h deleted file mode 100644 index e35c68e..0000000 --- a/list/list_easy.h +++ /dev/null @@ -1,72 +0,0 @@ -#include "list.h" - -#ifndef LIST_EASY_H -#define LIST_EASY_H - -Node *new_nodeWithInt(int); -Node *new_nodeWithDouble(double); -Node *new_nodeWithString(const char *); -Node *new_nodeWithPointer(void *); -Node *find_nodeByIndex(List *, unsigned long long); -int list_through(List *p_list, int (*p_func)(void *, const char *));//Go through the list.Call p_func every time. - - -Node *new_nodeWithInt(int m_int){ - int *p_int = (int *)malloc(sizeof(int)); - *p_int = m_int; - Node *p_node = init_node(); - init_value(p_node,"int",(void *)p_int); - return p_node; -} - -Node *new_nodeWithDouble(double m_double){ - double *p_double = (double *)malloc(sizeof(double)); - *p_double = m_double; - Node *p_node = init_node(); - init_value(p_node,"double",(void *)p_double); - return p_node; -} - -Node *new_nodeWithString(const char *m_string){ - char *p_string = (char *)malloc(sizeof(char)*(strlen(m_string)+1)); - strcpy(p_string,m_string); - Node *p_node = init_node(); - init_value(p_node,"string",(void *)p_string); - return p_node; -} - -Node *new_nodeWithPointer(void *m_pointer){ - Node *p_node = init_node(); - init_value(p_node,"pointer",(void *)m_pointer); - return p_node; -} - -Node *find_nodeByIndex(List *p_list, unsigned long long m_index){ - Node *p_node = p_list->head; - for(unsigned long long i= 0; i < m_index; i++){ - p_node = p_node->next; - } - return p_node; -} - -int list_through(List *p_list, int (*p_func)(void *, const char *)){ - Node *p_node = p_list->head; - while(p_node != NULL){ - if(p_node->if_setvalue == 1){ - int m_return = (*p_func)(p_node->value, p_node->type); - if (m_return == -1) break; - else if (m_return == 1){ - p_node = p_node->last; - continue; - } - else{ - - } - } - p_node = p_node->next; - } - return 0; -} - - -#endif diff --git a/list/list_expand.h b/list/list_expand.h new file mode 100644 index 0000000..d75c22d --- /dev/null +++ b/list/list_expand.h @@ -0,0 +1,298 @@ +#include "list.h" +#include + +#ifndef LIST_EASY_H +#define LIST_EASY_H + +Node *nodeWithInt(int);//快速初始化一个单一值节点并赋值 +Node *nodeWithDouble(double);//快速初始化一个节单一值点并赋值 +Node *nodeWithString(const char *);//快速初始化一个单一值节点并赋值 +Node *nodeWithPointer(void *);//快速初始化一个单一值节点并赋值 + +Node *nodeWithComplex(void);//快速初始化一个复合值节点并赋值 +int addValueForComplex(Node *, char *type, void *value);//为复合节点添加值 +int addIntForComplex(Node *, int);//为复合节点添加一个特定类型的值 +int addDoubleForComplex(Node *, double);//为复合节点添加一个特定类型的值 +int addStringForComplex(Node *, char *);//为复合节点添加一个特定类型的值 +int addPointerForComplex(Node *, void *);//为复合节点添加一个特定类型的值 + +Node *findByIndex(List *, unsigned long long);//根据位置查找一个节点 +Node *findByInt(List *, int);//依照特定类型查找一个节点 +Node *findByDouble(List *, double);//依照特定类型查找一个节点 +Node *findByString(List *, char *);//依照特定类型查找一个节点 +Node *findByPointer(List *, void *);//依照特定类型查找一个节点 + +void printListInfo(List *p_list,int priority);//打印列表的详细信息 +void printNodeInfo(Node *p_node,int priority);//打印节点的详细信息 +void printList(List *);//打印列表 +void printNode(Node *p_node);//打印节点 + +int getByInt(Node *);//直接得到节点的值 +double getByDouble(Node *);//直接得到节点的值 +char *getByString(Node *);//直接得到节点的值 +void *getByPointer(Node *);//直接得到节点的值 +int listThrough(List *p_list, int (*p_func)(void *, const char *));//遍历链表并不断调用目标函数。目标函数将接受节点储存值的指针及其类型。 + + +Node *nodeWithInt(int m_int){ + int *p_int = (int *)malloc(sizeof(int)); + *p_int = m_int; + Node *p_node = init_node(); + initMallocValue(p_node,"int",(void *)p_int); + return p_node; +} + +Node *nodeWithDouble(double m_double){ + double *p_double = (double *)malloc(sizeof(double)); + *p_double = m_double; + Node *p_node = init_node(); + initMallocValue(p_node,"double",(void *)p_double); + return p_node; +} + +Node *nodeWithString(const char *m_string){ + char *p_string = (char *)malloc(sizeof(char)*(strlen(m_string)+1)); + strcpy(p_string,m_string); + Node *p_node = init_node(); + initMallocValue(p_node,"string",(void *)p_string); + return p_node; +} + +Node *nodeWithPointer(void *m_pointer){ + Node *p_node = init_node(); + initMallocValue(p_node,"pointer",m_pointer); + return p_node; +} + +Node *nodeWithComplex(void){ + Node *p_node = init_node(); + p_node->type = "list"; + p_node->value = init_list(); + p_node->if_malloc = 1; + return p_node; +} + +Node *findByIndex(List *p_list, unsigned long long m_index){ + Node *p_node = p_list->head; + for(unsigned long long i= 0; i < m_index; i++){ + p_node = p_node->next; + } + return p_node; +} + +int listThrough(List *p_list, int (*p_func)(void *, const char *)){ + Node *p_node = p_list->head; + while(p_node != NULL){ + if(p_node->if_malloc == 1){ + int m_return = (*p_func)(p_node->value, p_node->type); + if (m_return == -1) break; + else if (m_return == 1){ + p_node = p_node->last; + continue; + } + else{ + + } + } + p_node = p_node->next; + } + return 0; +} + +int getByInt(Node *p_node){ + if (strcmp(p_node->type, "int")) return *(int *)(p_node->value); + else return -1; +} + +char *getByString(Node *p_node){ + if (strcmp(p_node->type, "string")) return (char *)(p_node->value); + else return NULL; +} + +double getByDouble(Node *p_node){ + if (strcmp(p_node->type, "double")) return *(double *)(p_node->value); + else return -1; +} + +void *getByPointer(Node *p_node){ + if (strcmp(p_node->type, "pointer")) return (void *)(p_node->value); + else return NULL; +} + +void printListInfo(List *p_list,int priority){ + for(int i = 0; i < priority; i++) printf(" "); + printf("###LIST(location:%p, id:%llu){\n",p_list,p_list->id); + for(int i = 0; i < priority+1; i++) printf(" "); + printf("HEAD->%p / Tail->%p / Length:%llu\n",p_list->head,p_list->tail,p_list->length); + Node *p_node = p_list->head; + int i = 0; + while (p_node != NULL){ + for(int i = 0; i < priority+1; i++) printf(" "); + printf("%d.... \n",i); + printNodeInfo(p_node, priority+1); + p_node = p_node->next; + i++; + } + for(int i = 0; i < priority; i++) printf(" "); + printf("}\n"); + +} + +void printNodeInfo(Node *p_node,int priority){ + for(int i = 0; i < priority; i++) printf(" "); + printf("#NODE(location:%p, id:%llu){\n",p_node,p_node->id); + for(int i = 0; i < priority+1; i++) printf(" "); + 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)); + } + 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)); + } + 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)); + } + 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)); + } + else if(!strcmp(p_node->type, "list")){ + for(int i = 0; i < priority+1; i++) printf(" "); + printf("VALUE(List):\n"); + printListInfo((List *)p_node->value,priority+2); + } + for(int i = 0; i < priority; i++) printf(" "); + printf("}\n"); +} + +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("}\n"); +} + +void printList(List *p_list){ + Node *p_node = p_list->head; + printf("["); + int if_nearLast = 0; + while (p_node != NULL) { + if(!if_nearLast && p_node->next == NULL) if_nearLast = 1; + if(!strcmp(p_node->type, "int")){ + printf("%d",*(int *)(p_node->value)); + } + else if(!strcmp(p_node->type, "double")){ + printf("%a",*(double *)(p_node->value)); + } + else if(!strcmp(p_node->type, "string")){ + printf("%s",(char *)(p_node->value)); + } + else if(!strcmp(p_node->type, "pointer")){ + printf("%s",(char *)(p_node->value)); + } + else if(!strcmp(p_node->type, "list")){ + printList((List *)p_node->value); + } + if(!if_nearLast){ + printf(", "); + } + p_node = p_node->next; + } + printf("]"); +} + +Node *findByInt(List *p_list, int target){ + int *p_target = (int *)malloc(sizeof(int)); + *p_target = target; + Node *t_node = findByValue(p_list, "int", p_target); + free(p_target); + return t_node; +} + +Node *findByDouble(List *p_list, double target){ + double *p_target = (double *)malloc(sizeof(double)); + *p_target = target; + Node *t_node = findByValue(p_list, "double", p_target); + free(p_target); + return t_node; +} + +Node *findByString(List *p_list, char *target){ + Node *t_node = findByValue(p_list, "string", target); + return t_node; +} + +Node *findByPointer(List *p_list, void *target){ + Node *t_node = findByValue(p_list, "pointer", target); + return t_node; +} + +int addValueForComplex(Node * p_node, char *type, void *value){ + if(!strcmp(p_node->type ,"list")){ + List *c_list = (List *)p_node->value; + Node *c_node = init_node(); + initMallocValue(c_node, type, value); + insertInTail(c_list, c_node); + return 0; + } + return -1; +} + +int addIntForComplex(Node *p_node, int temp){ + if(!strcmp(p_node->type, "list")){ + int *p_temp = (int *)malloc(sizeof(int)); + *p_temp = temp; + addValueForComplex(p_node, "int", p_temp); + return 0; + } + return -1; +} + +int addDoubleForComplex(Node *p_node, double temp){ + if(!strcmp(p_node->type, "list")){ + double *p_temp = (double *)malloc(sizeof(double)); + *p_temp = temp; + addValueForComplex(p_node, "double", p_temp); + return 0; + } + return -1; +} + +int addStringForComplex(Node *p_node, char *temp){ + if(!strcmp(p_node->type, "list")){ + char *p_temp = (char *)malloc(sizeof(strlen(temp)+1)); + strcpy(p_temp, temp); + addValueForComplex(p_node, "string", p_temp); + return 0; + } + return -1; +} + +int addPointerForComplex(Node *p_node, void *temp){ + if(!strcmp(p_node->type, "list")){ + addValueForComplex(p_node, "pointer", temp); + return 0; + } + return -1; +} + +#endif From d3550aa26b97d78e693e8474027ad3cfb8d8cc7a Mon Sep 17 00:00:00 2001 From: Saturneic Date: Sun, 10 Jun 2018 17:47:57 +0800 Subject: [PATCH 09/31] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E4=BA=86=E4=B8=80?= =?UTF-8?q?=E4=BA=9B=E5=8A=9F=E8=83=BD=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- list/list.h | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/list/list.h b/list/list.h index 9c74c6d..180081a 100644 --- a/list/list.h +++ b/list/list.h @@ -41,6 +41,9 @@ unsigned long long getId(void); int insertInHead(List *p_list, Node *p_node); int insertInTail(List *p_list, Node *p_node); +/*交换函数*/ +int exchangeLocation(Node *p_node,Node *t_node); + /*移除函数*/ int removeById(List *p_list, unsigned long id); int removeByNode(List *p_list, Node *p_node); @@ -467,4 +470,18 @@ int isListEmpty(List *p_list){ return 0; // want to make a list empty. } +int exchangeLocation(Node *p_node,Node *t_node){ + Node *temp_next = p_node->next; + Node *temp_last = p_node->last; + p_node->last->next = t_node; + p_node->next->last = t_node; + t_node->last->next = p_node; + t_node->next->last = p_node; + p_node->next = t_node->next; + p_node->last = t_node->last; + t_node->next = temp_next; + t_node->last = temp_last; + return 0; +} + #endif From 510b191de5fd63f320c62d078a802bab75c9250e Mon Sep 17 00:00:00 2001 From: Saturneic Date: Mon, 11 Jun 2018 15:00:08 +0800 Subject: [PATCH 10/31] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=B9=B6=E4=BF=AE?= =?UTF-8?q?=E6=94=B9=E4=BA=86=E4=B8=80=E4=BA=9B=E5=87=BD=E6=95=B0=EF=BC=8C?= =?UTF-8?q?=E5=BC=80=E5=A7=8B=E5=86=99=E6=A0=88=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- list/list.c | 16 ++++++------- list/list.h | 60 +++++++++++++++++++++++++++++++++------------- list/list_expand.h | 39 +++++++++++++++++++++++++++++- stack/stack.c | 14 +++++++++++ stack/stack.h | 37 ++++++++++++++++++++++++++++ 5 files changed, 141 insertions(+), 25 deletions(-) create mode 100644 stack/stack.c create mode 100644 stack/stack.h diff --git a/list/list.c b/list/list.c index 9bcf50f..91bb75c 100644 --- a/list/list.c +++ b/list/list.c @@ -9,6 +9,7 @@ int main(int argc, char **argv){ rand_init(); + safeMode(1); List *t_list = init_list(); /*for(int i = 0; i < 9; i++){ @@ -25,20 +26,19 @@ int main(int argc, char **argv){ for(int i = 0; i < 12; i++){ insertInHead(t_list, nodeWithInt(i)); + insertInTail(t_list, nodeWithInt(i)); } - Node *t_node = nodeWithComplex(); - addIntForComplex(t_node, 32); - addIntForComplex(t_node, 64); - insertInTail(t_list, t_node); - insertInTail(t_list, nodeWithDouble(32.5)); - insertInTail(t_list, nodeWithString("There")); - printNodeInfo(findByString(t_list, "There"), 0); + printListInfo(t_list,0); printList(t_list); + List *m_list; + m_list = m_findByInt(t_list, 5); + printList(m_list); printf("\n"); - releaseList(t_list); + + releaseAll(); return 0; } diff --git a/list/list.h b/list/list.h index 180081a..3081af7 100644 --- a/list/list.h +++ b/list/list.h @@ -44,6 +44,9 @@ int insertInTail(List *p_list, Node *p_node); /*交换函数*/ int exchangeLocation(Node *p_node,Node *t_node); +/*复制函数*/ +Node *copyNode(Node *); + /*移除函数*/ int removeById(List *p_list, unsigned long id); int removeByNode(List *p_list, Node *p_node); @@ -61,6 +64,7 @@ int releaseListForSingle(List *p_list);//单独释放List int releaseNode(Node *p_node);//释放Node int isListEmpty(List *p_list);//判断List是否为空 +List *copyList(List *p_list);//复制链表 /*有关安全模式的变量*/ int if_safeMode = 0; @@ -397,23 +401,23 @@ Node *findByValue(List *p_list, const char *type, const void *value){ } if(!strcmp(type,"int")){ if(*((int *)p_node->value) == *((int *)value)){ - return p_node; + return copyNode(p_node); } } else if(!strcmp(type,"double")){ if(*((double *)p_node->value) == *((double *)value)){ - return p_node; + return copyNode(p_node); } } else if(!strcmp (type,"string")){ if(!strcmp((char *)p_node->value,(char *)value)) { - return p_node; + return copyNode(p_node); } } else if(!strcmp(type,"pointer")){ if(p_node->value == value){ - return p_node; + return copyNode(p_node); } } @@ -427,34 +431,33 @@ List *mply_findByValue(List *p_list, const char *type, const void *value){ List *f_list = init_list(); Node *p_node = p_list->head; while(p_node != NULL){ - if(strcmp(p_node->type,type)) continue; + if(strcmp(p_node->type,type)){ + p_node = p_node->next; + continue; + } if(!strcmp(type,"int")){ if(*((int *)p_node->value) == *((int *)value)){ - Node *f_node = init_node(); - initMallocValue(f_node,"pointer",(void *)p_node); + Node *f_node = copyNode(p_node); insertInTail(f_list,f_node); } } else if(!strcmp(type,"double")){ if(*((double *)p_node->value) == *((double *)value)){ - Node *f_node = init_node(); - initMallocValue(f_node,"pointer",(void *)p_node); - insertInTail(f_list,f_node); + Node *f_node = copyNode(p_node); + insertInTail(f_list,f_node); } } else if(!strcmp (type,"string")){ if(!strcmp((char *)p_node->value,(char *)value)) { - Node *f_node = init_node(); - initMallocValue(f_node,"pointer",(void *)p_node); - insertInTail(f_list,f_node); + Node *f_node = copyNode(p_node); + insertInTail(f_list,f_node); } } else if(!strcmp(type,"pointer")){ if(p_node->value == value){ - Node *f_node = init_node(); - initMallocValue(f_node,"pointer",(void *)p_node); - insertInTail(f_list,f_node); + Node *f_node = copyNode(p_node); + insertInTail(f_list,f_node); } } @@ -484,4 +487,29 @@ int exchangeLocation(Node *p_node,Node *t_node){ return 0; } +Node *copyNode(Node *p_node){ + Node *t_node = init_node(); + t_node->id = p_node->id; + t_node->last = p_node->last; + t_node->next = p_node->next; + t_node->if_malloc = p_node->if_malloc; + t_node->type = p_node->type; + t_node->value = p_node->value; + return t_node; +} + +List *copyList(List *p_list){ + List *t_list = init_list(); + t_list->head = p_list->head; + t_list->tail = p_list->tail; + t_list->id = p_list->id; + Node *p_node = p_list->head; + while(p_node != NULL){ + Node *t_node = copyNode(p_node); + insertInTail(t_list, t_node); + p_node = p_node->next; + } + return t_list; +} + #endif diff --git a/list/list_expand.h b/list/list_expand.h index d75c22d..388756d 100644 --- a/list/list_expand.h +++ b/list/list_expand.h @@ -22,6 +22,11 @@ Node *findByDouble(List *, double);//依照特定类型查找一个节点 Node *findByString(List *, char *);//依照特定类型查找一个节点 Node *findByPointer(List *, void *);//依照特定类型查找一个节点 +List *m_findByInt(List*, int);//根据位置查找所有匹配的节点 +List *m_findByDouble(List*, double);//根据位置查找所有匹配的节点 +List *m_findByString(List*, char *);//根据位置查找所有匹配的节点 +List *m_findByPointer(List*, void *);//根据位置查找所有匹配的节点 + void printListInfo(List *p_list,int priority);//打印列表的详细信息 void printNodeInfo(Node *p_node,int priority);//打印节点的详细信息 void printList(List *);//打印列表 @@ -237,7 +242,10 @@ Node *findByDouble(List *p_list, double target){ } Node *findByString(List *p_list, char *target){ - Node *t_node = findByValue(p_list, "string", target); + char *p_temp = (char *)malloc(sizeof(char)*(strlen(target)+1)); + strcpy(p_temp, target); + Node *t_node = findByValue(p_list, "string", p_temp); + free(p_temp); return t_node; } @@ -295,4 +303,33 @@ int addPointerForComplex(Node *p_node, void *temp){ return -1; } +List *m_findByInt(List* p_list, int temp){ + int *p_temp = (int *)malloc(sizeof(int)); + *p_temp = temp; + List *t_list = mply_findByValue(p_list, "int", (void *)p_temp); + free(p_temp); + return t_list; +} + +List *m_findByDouble(List* p_list, double temp){ + double *p_temp = (double *)malloc(sizeof(double)); + *p_temp = temp; + List *t_list = mply_findByValue(p_list, "double", (void *)p_temp); + free(p_temp); + return t_list; +} + +List *m_findByString(List* p_list, char *temp){ + char *p_temp = (char *)malloc(sizeof(char)*(strlen(temp)+1)); + strcpy(p_temp, temp); + List *t_list = mply_findByValue(p_list, "string", (void *)p_temp); + free(p_temp); + return t_list; +} + +List *m_findByPointer(List* p_list, void *temp){ + List *t_list = mply_findByValue(p_list, "double", (void *)temp); + return t_list; +} + #endif diff --git a/stack/stack.c b/stack/stack.c new file mode 100644 index 0000000..347880c --- /dev/null +++ b/stack/stack.c @@ -0,0 +1,14 @@ +// +// stack.c +// ZE-Standard-Libraries +// +// Created by 胡一兵 on 2018/6/11. +// Copyright © 2018年 ZE. All rights reserved. +// + +#include "stack.h" + +int main(int argc, char **argv){ + + return 0; +} diff --git a/stack/stack.h b/stack/stack.h new file mode 100644 index 0000000..83b4e4e --- /dev/null +++ b/stack/stack.h @@ -0,0 +1,37 @@ +// +// stack.h +// ZE-Standard-Libraries +// +// Created by 胡一兵 on 2018/6/11. +// Copyright © 2018年 ZE. All rights reserved. +// + +#ifndef stack_h +#define stack_h + +#include "list.h" + +typedef struct stack_node{ + unsigned long long id; + int if_malloc; + void *value; + struct stack_node *next; +} SNode; + +typedef struct stack{ + unsigned long long id; + unsigned long long length; + SNode *top; +} Stack; + +Stack *initStack(void); +SNode *initSNode(void); + +SNode *popStack(Stack *p_stack); +int pushStack(Stack *p_stack, SNode *p_snode); + +int releaseStack(Stack *p_stack); +int releaseSNode(SNode *p_snode); + + +#endif /* stack_h */ From bda6e3fea7a42af2115daff18e75d18cfbbd514d Mon Sep 17 00:00:00 2001 From: Saturneic Date: Mon, 11 Jun 2018 15:28:34 +0800 Subject: [PATCH 11/31] =?UTF-8?q?Stack=E4=B8=BB=E4=BD=93=E5=AE=8C=E6=88=90?= =?UTF-8?q?=E3=80=82=E5=85=B6=E4=BB=96=E7=A8=8D=E4=BD=9C=E4=BF=AE=E6=94=B9?= =?UTF-8?q?=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- list/list.h | 8 +++--- list/list_expand.h | 18 ++++++------ stack/stack.h | 68 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 81 insertions(+), 13 deletions(-) diff --git a/list/list.h b/list/list.h index 3081af7..96a94d1 100644 --- a/list/list.h +++ b/list/list.h @@ -31,7 +31,7 @@ int releaseAll(void);//安全模式最后调用的函数 List *init_list(void); Node *init_node(void); -int initMallocValue(Node *,const char *,void *);//赋予已分配内存的值,并标明类型 +int initMalllocValueForNode(Node *,const char *,void *);//赋予已分配内存的值,并标明类型 /*有关id的函数*/ void init_rand(void); @@ -156,7 +156,7 @@ Node *init_node(void){ if_safeMode = 0; Node *prec_node = init_node(); if_safeMode = 1; - initMallocValue(prec_node, "pointer", (void *)p_node); + initMalllocValueForNode(prec_node, "pointer", (void *)p_node); insertInTail(node_list,prec_node); } return p_node; @@ -172,13 +172,13 @@ List *init_list(void){ if_safeMode = 0; Node *p_node = init_node(); if_safeMode = 1; - initMallocValue(p_node,"pointer",(void *)p_list); + initMalllocValueForNode(p_node,"pointer",(void *)p_list); insertInTail(list_list,p_node); } return p_list; } -int initMallocValue(Node *p_node,const char *type,void *p_value){ +int initMalllocValueForNode(Node *p_node,const char *type,void *p_value){ p_node->if_malloc = 1; p_node->type = type; p_node->value = p_value; diff --git a/list/list_expand.h b/list/list_expand.h index 388756d..39d7390 100644 --- a/list/list_expand.h +++ b/list/list_expand.h @@ -43,7 +43,7 @@ Node *nodeWithInt(int m_int){ int *p_int = (int *)malloc(sizeof(int)); *p_int = m_int; Node *p_node = init_node(); - initMallocValue(p_node,"int",(void *)p_int); + initMalllocValueForNode(p_node,"int",(void *)p_int); return p_node; } @@ -51,7 +51,7 @@ Node *nodeWithDouble(double m_double){ double *p_double = (double *)malloc(sizeof(double)); *p_double = m_double; Node *p_node = init_node(); - initMallocValue(p_node,"double",(void *)p_double); + initMalllocValueForNode(p_node,"double",(void *)p_double); return p_node; } @@ -59,13 +59,13 @@ Node *nodeWithString(const char *m_string){ char *p_string = (char *)malloc(sizeof(char)*(strlen(m_string)+1)); strcpy(p_string,m_string); Node *p_node = init_node(); - initMallocValue(p_node,"string",(void *)p_string); + initMalllocValueForNode(p_node,"string",(void *)p_string); return p_node; } Node *nodeWithPointer(void *m_pointer){ Node *p_node = init_node(); - initMallocValue(p_node,"pointer",m_pointer); + initMalllocValueForNode(p_node,"pointer",m_pointer); return p_node; } @@ -105,22 +105,22 @@ int listThrough(List *p_list, int (*p_func)(void *, const char *)){ } int getByInt(Node *p_node){ - if (strcmp(p_node->type, "int")) return *(int *)(p_node->value); + if (!strcmp(p_node->type, "int")) return *(int *)(p_node->value); else return -1; } char *getByString(Node *p_node){ - if (strcmp(p_node->type, "string")) return (char *)(p_node->value); + if (!strcmp(p_node->type, "string")) return (char *)(p_node->value); else return NULL; } double getByDouble(Node *p_node){ - if (strcmp(p_node->type, "double")) return *(double *)(p_node->value); + if (!strcmp(p_node->type, "double")) return *(double *)(p_node->value); else return -1; } void *getByPointer(Node *p_node){ - if (strcmp(p_node->type, "pointer")) return (void *)(p_node->value); + if (!strcmp(p_node->type, "pointer")) return (void *)(p_node->value); else return NULL; } @@ -258,7 +258,7 @@ int addValueForComplex(Node * p_node, char *type, void *value){ if(!strcmp(p_node->type ,"list")){ List *c_list = (List *)p_node->value; Node *c_node = init_node(); - initMallocValue(c_node, type, value); + initMalllocValueForNode(c_node, type, value); insertInTail(c_list, c_node); return 0; } diff --git a/stack/stack.h b/stack/stack.h index 83b4e4e..d2d64ea 100644 --- a/stack/stack.h +++ b/stack/stack.h @@ -14,6 +14,7 @@ typedef struct stack_node{ unsigned long long id; int if_malloc; + const char *type; void *value; struct stack_node *next; } SNode; @@ -26,6 +27,7 @@ typedef struct stack{ Stack *initStack(void); SNode *initSNode(void); +int initMallocValueForSNode(SNode *p_snode, const char *type, void *value); SNode *popStack(Stack *p_stack); int pushStack(Stack *p_stack, SNode *p_snode); @@ -33,5 +35,71 @@ int pushStack(Stack *p_stack, SNode *p_snode); int releaseStack(Stack *p_stack); int releaseSNode(SNode *p_snode); +Stack *initStack(void){ + Stack *p_stack = (Stack *)malloc(sizeof(Stack)); + p_stack->id = getId(); + p_stack->length = 0; + p_stack->top = NULL; + return p_stack; +} + +SNode *initSNode(void){ + SNode *p_snode = (SNode *)malloc(sizeof(SNode)); + p_snode->id = getId(); + p_snode->if_malloc = 0; + p_snode->next = NULL; + p_snode->value = NULL; + return p_snode; +} + +SNode *popStack(Stack *p_stack){ + if(p_stack->top != NULL){ + SNode *p_snode = p_stack->top; + p_stack->top = p_snode->next; + p_snode->next = NULL; + p_stack->length -= 1; + return p_snode; + } + else return NULL; +} + +int pushStack(Stack *p_stack, SNode *p_snode){ + SNode *pn_snode = p_stack->top; + p_stack->top = p_snode; + p_snode->next = pn_snode; + p_stack->length -= 1; + return 0; +} + +int releaseStack(Stack *p_stack){ + SNode *p_sndoe = p_stack->top; + while(p_sndoe != NULL){ + SNode *pl_snode = p_sndoe; + p_sndoe = p_sndoe->next; + releaseSNode(pl_snode); + } + p_stack->id = 0; + p_stack->top = NULL; + p_stack->length = 0; + free(p_stack); + return 0; +} + +int releaseSNode(SNode *p_snode){ + p_snode->id = 0; + free(p_snode->value); + p_snode->if_malloc = 0; + p_snode->value = NULL; + p_snode->type = NULL; + free(p_snode); + return 0; +} + +int initMallocValueForSNode(SNode *p_snode, const char *type, void *value){ + p_snode->if_malloc = 1; + p_snode->type = type; + p_snode->value = value; + return 0; +} #endif /* stack_h */ From a8525b639bba80332c59f785269f289efb3f7995 Mon Sep 17 00:00:00 2001 From: Saturneic Date: Mon, 11 Jun 2018 15:57:25 +0800 Subject: [PATCH 12/31] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- list/list_expand.h | 44 +++++++++++++------------- stack/stack.c | 2 +- stack/stack_expand.h | 74 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 97 insertions(+), 23 deletions(-) create mode 100644 stack/stack_expand.h diff --git a/list/list_expand.h b/list/list_expand.h index 39d7390..b0cf0be 100644 --- a/list/list_expand.h +++ b/list/list_expand.h @@ -16,26 +16,26 @@ int addDoubleForComplex(Node *, double);//为复合节点添加一个特定类 int addStringForComplex(Node *, char *);//为复合节点添加一个特定类型的值 int addPointerForComplex(Node *, void *);//为复合节点添加一个特定类型的值 -Node *findByIndex(List *, unsigned long long);//根据位置查找一个节点 -Node *findByInt(List *, int);//依照特定类型查找一个节点 -Node *findByDouble(List *, double);//依照特定类型查找一个节点 -Node *findByString(List *, char *);//依照特定类型查找一个节点 -Node *findByPointer(List *, void *);//依照特定类型查找一个节点 +Node *findByIndexForNode(List *, unsigned long long);//根据位置查找一个节点 +Node *findByIntForNode(List *, int);//依照特定类型查找一个节点 +Node *findByDoubleForNode(List *, double);//依照特定类型查找一个节点 +Node *findByStringForNode(List *, char *);//依照特定类型查找一个节点 +Node *findByPointerForNode(List *, void *);//依照特定类型查找一个节点 -List *m_findByInt(List*, int);//根据位置查找所有匹配的节点 -List *m_findByDouble(List*, double);//根据位置查找所有匹配的节点 -List *m_findByString(List*, char *);//根据位置查找所有匹配的节点 -List *m_findByPointer(List*, void *);//根据位置查找所有匹配的节点 +List *m_findByIntForNode(List*, int);//根据位置查找所有匹配的节点 +List *m_findByDoubleForNode(List*, double);//根据位置查找所有匹配的节点 +List *m_findByStringForNode(List*, char *);//根据位置查找所有匹配的节点 +List *m_findByPointerForNode(List*, void *);//根据位置查找所有匹配的节点 void printListInfo(List *p_list,int priority);//打印列表的详细信息 void printNodeInfo(Node *p_node,int priority);//打印节点的详细信息 void printList(List *);//打印列表 void printNode(Node *p_node);//打印节点 -int getByInt(Node *);//直接得到节点的值 -double getByDouble(Node *);//直接得到节点的值 -char *getByString(Node *);//直接得到节点的值 -void *getByPointer(Node *);//直接得到节点的值 +int getByIntForNode(Node *);//直接得到节点的值 +double getByDoubleForNode(Node *);//直接得到节点的值 +char *getByStringForNode(Node *);//直接得到节点的值 +void *getByPointerForNode(Node *);//直接得到节点的值 int listThrough(List *p_list, int (*p_func)(void *, const char *));//遍历链表并不断调用目标函数。目标函数将接受节点储存值的指针及其类型。 @@ -77,7 +77,7 @@ Node *nodeWithComplex(void){ return p_node; } -Node *findByIndex(List *p_list, unsigned long long m_index){ +Node *findByIndexForNode(List *p_list, unsigned long long m_index){ Node *p_node = p_list->head; for(unsigned long long i= 0; i < m_index; i++){ p_node = p_node->next; @@ -104,22 +104,22 @@ int listThrough(List *p_list, int (*p_func)(void *, const char *)){ return 0; } -int getByInt(Node *p_node){ +int getByIntForNode(Node *p_node){ if (!strcmp(p_node->type, "int")) return *(int *)(p_node->value); else return -1; } -char *getByString(Node *p_node){ +char *getByStringForNode(Node *p_node){ if (!strcmp(p_node->type, "string")) return (char *)(p_node->value); else return NULL; } -double getByDouble(Node *p_node){ +double getByDoubleForNode(Node *p_node){ if (!strcmp(p_node->type, "double")) return *(double *)(p_node->value); else return -1; } -void *getByPointer(Node *p_node){ +void *getByPointerForNode(Node *p_node){ if (!strcmp(p_node->type, "pointer")) return (void *)(p_node->value); else return NULL; } @@ -225,7 +225,7 @@ void printList(List *p_list){ printf("]"); } -Node *findByInt(List *p_list, int target){ +Node *findByIntForNode(List *p_list, int target){ int *p_target = (int *)malloc(sizeof(int)); *p_target = target; Node *t_node = findByValue(p_list, "int", p_target); @@ -233,7 +233,7 @@ Node *findByInt(List *p_list, int target){ return t_node; } -Node *findByDouble(List *p_list, double target){ +Node *findByDoubleForNode(List *p_list, double target){ double *p_target = (double *)malloc(sizeof(double)); *p_target = target; Node *t_node = findByValue(p_list, "double", p_target); @@ -241,7 +241,7 @@ Node *findByDouble(List *p_list, double target){ return t_node; } -Node *findByString(List *p_list, char *target){ +Node *findByStringForNode(List *p_list, char *target){ char *p_temp = (char *)malloc(sizeof(char)*(strlen(target)+1)); strcpy(p_temp, target); Node *t_node = findByValue(p_list, "string", p_temp); @@ -249,7 +249,7 @@ Node *findByString(List *p_list, char *target){ return t_node; } -Node *findByPointer(List *p_list, void *target){ +Node *findByPointerForNode(List *p_list, void *target){ Node *t_node = findByValue(p_list, "pointer", target); return t_node; } diff --git a/stack/stack.c b/stack/stack.c index 347880c..02f8e00 100644 --- a/stack/stack.c +++ b/stack/stack.c @@ -6,7 +6,7 @@ // Copyright © 2018年 ZE. All rights reserved. // -#include "stack.h" +#include "stack_expand.h" int main(int argc, char **argv){ diff --git a/stack/stack_expand.h b/stack/stack_expand.h new file mode 100644 index 0000000..5db29eb --- /dev/null +++ b/stack/stack_expand.h @@ -0,0 +1,74 @@ +// +// stack_expand.h +// ZE-Standard-Libraries +// +// Created by 胡一兵 on 2018/6/11. +// Copyright © 2018年 ZE. All rights reserved. +// + +#ifndef stack_expand_h +#define stack_expand_h + +#include "stack.h" + +SNode *snodeWithInt(int); +SNode *snodeWithDouble(double); +SNode *snodeWithString(char *); +SNode *snodeWithPointer(void *); + +int getValueByIntForSNode(SNode *); +double getValueByDoubleForSNode(SNode *); +char *getValueByStringForSNode(SNode *); +void *getValueByPointerForSNode(SNode *); + +SNode *snodeWithInt(int temp){ + SNode *p_snode = initSNode(); + int *p_temp = (int *)malloc(sizeof(int)); + *p_temp = temp; + initMallocValueForSNode(p_snode, "int", p_temp); + return p_snode; +} + +SNode *snodeWithDouble(double temp){ + SNode *p_snode = initSNode(); + double *p_temp = (double *)malloc(sizeof(double)); + *p_temp = temp; + initMallocValueForSNode(p_snode, "double", p_temp); + return p_snode; +} + +SNode *snodeWithString(char *temp){ + SNode *p_snode = initSNode(); + char *p_temp = (char *)malloc(sizeof(char)*(strlen(temp)+1)); + strcpy(p_temp, temp); + initMallocValueForSNode(p_snode, "string", p_temp); + return p_snode; +} + +SNode *snodeWithPointer(void *temp){ + SNode *p_snode = initSNode(); + initMallocValueForSNode(p_snode, "pointer", temp); + return p_snode; +} + +int getValueByIntForSNode(SNode *p_snode){ + if(!strcmp(p_snode->type, "int")) return *(int *)p_snode->value; + else return -1; +} + +double getValueByDoubleForSNode(SNode *p_snode){ + if(!strcmp(p_snode->type, "double")) return *(double *)p_snode->value; + else return -1; +} + +char *getValueByStringForSNode(SNode *p_snode){ + if(!strcmp(p_snode->type, "int")) return (char *)p_snode->value; + else return NULL; +} + +void *getValueByPointerForSNode(SNode *p_snode){ + if(!strcmp(p_snode->type, "int")) return (void *)p_snode->value; + else return NULL; +} + +#endif /* stack_expand_h */ From 785a6236faafb2c0a4c1f6e47da355c3a934a16b Mon Sep 17 00:00:00 2001 From: Saturneic Date: Mon, 11 Jun 2018 16:00:48 +0800 Subject: [PATCH 13/31] =?UTF-8?q?=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- stack/stack.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/stack/stack.c b/stack/stack.c index 02f8e00..7d22fd2 100644 --- a/stack/stack.c +++ b/stack/stack.c @@ -9,6 +9,13 @@ #include "stack_expand.h" int main(int argc, char **argv){ - + Stack *t_stack = initStack(); + for(int i = 0; i < 10; i++){ + pushStack(t_stack, snodeWithInt(i)); + } + for(int i = 0; i < 10; i++){ + printf("%d",getValueByIntForSNode(popStack(t_stack))); + } + releaseStack(t_stack); return 0; } From 768eee06df2927a1a6eb89c9ba12f31dd705d508 Mon Sep 17 00:00:00 2001 From: Saturneric Date: Tue, 12 Jun 2018 13:46:59 +0800 Subject: [PATCH 14/31] =?UTF-8?q?=E5=87=BA=E7=8E=B0=E4=BA=86=E6=84=8F?= =?UTF-8?q?=E5=A4=96=E9=87=8D=E6=96=B0=E6=95=B4=E7=90=86=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..c79cf27 --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ +################################################################################ +# 此 .gitignore 文件已由 Microsoft(R) Visual Studio 自动创建。 +################################################################################ + +/Debug From c1568c3a5f4008f34ea2270660fcbcfde3b411db Mon Sep 17 00:00:00 2001 From: Saturneric Date: Tue, 12 Jun 2018 13:51:42 +0800 Subject: [PATCH 15/31] =?UTF-8?q?=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 3 +++ list/list.c | Bin 1075 -> 2172 bytes list/list.h | Bin 11910 -> 23946 bytes list/list_expand.h | Bin 10906 -> 21118 bytes main.c | 10 ++++++++++ stack/stack.c | Bin 460 -> 588 bytes stack/stack.h | Bin 2250 -> 4426 bytes stack/stack_expand.h | Bin 1918 -> 3760 bytes tree/tree.c | 1 + tree/tree.h | 2 ++ 10 files changed, 16 insertions(+) create mode 100644 main.c create mode 100644 tree/tree.c create mode 100644 tree/tree.h diff --git a/.gitignore b/.gitignore index c79cf27..486a215 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,6 @@ ################################################################################ /Debug +/.vs/ZE-Standard-Libraries/v15 +/ZE-Standard-Libraries +/ZE-Standard-Libraries.sln di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*r@96x^xorb!f?tmr_Q9qPL;6^ zEzni#>#4CXdUnm5r~`UIRK;iZqsis0H?`XN6>qaQt5d@b{c>_}|4;pgSGKON4DbA| zfBDJq)mQMAfsytGFTNlWytchW`(M7s>S=!UXiaO^~*dSC~qwr$GW&(zKKoEcIC|$3G>tMA8|?EyX09l^iRa zr&ErS=YYP{Il=?C6GMts-BfVKBV>pZw2$#UxwDJPE5r217BXVLL_BHYHzs^L+|5H# z8`bb*@0;!Rtrjzcj!7Jh9fEw|wP);y@XHc-oB#boc%8cW_+oNtm0#JXuNH+IcSBG> zjvRbA0YK3~17ZwwQzbgb%Vm~+V^GG8$4v1Ffl(y;qw~(feJ68Q0hEG2=mm=Kz=@-=1syftEe%w_= z9(5E=`(64mM#YcSiKrJe)G<%ROHpreDORt=%5V|hN&S!psf&s)Cw694&oM90a=c->00M9gk5GzCqJ@yKqUG@J5{P|?k$t3 zLN_y_IKFhi#WJZik?B+!A<%{hLFx)2urDEn%8a?fuoIy+KcprPA6)|4|1Ao7W)kfj zmP$#>Ns1oAznlhFdx$B_kD8nvnw=2PrItR0+9@u2F##vHlj|;l_Ayh7kL{RQryG>U xt9NLiGXXYOU@yZii8kQJ*@yJ?s*bQl#mg-3rm^I!ZsTG!gIv7V3mbm3_+LSNJAnWI diff --git a/list/list_expand.h b/list/list_expand.h index b0cf0be4530c1bc0aff2226ddfbfe0273ba5e843..022e003ac94164e3e775cb19cd382249d9242c54 100644 GIT binary patch literal 21118 zcmdU1&5vA15pM;FFi5__3GuwEM6+urINTB&gkck9#eT)Jb`m*cS^g4KZMoOoJ8r{WcWZ8mKE3HKxG%c-V%!1U z(MuSOab0)Uo#yvtZjRm`xMO$XUUvKR33K9i&D}3XEYcnP{%sn0LZg=HFDI@|pYXci zuDY+$&p)=l`tet8{Q2E4b==zG+D-cR+Q#F@e>fbx|J`3)+ZZ+H63IAqcSxHa&Ag*N z#pi$gm?fmn-yuzpa*g+B{w~em&sUw%`+c`f*D|*_p|xz#>};DJ&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nb#oXtuSv=l~_DJD(ST-9pHxVNX0u&F^ z^#`c1uz*EMBqfyzm1sKp8 zA4s56AREi6vacKBc6@{{C;>G0x>PAa0Vy|r#_z@dWW9Z?rpHi{IkiKE2S#CisjuF<{fVy=S59nIL2 z$g6A88OXayCxFFV7v&vM>?RS`REjf@_D$~HXD2Rpi`hIkCo_%N5+LUn4ejWt#s`uc z)fI`#dg=f*Q~oSu_JmwY&3;3~7ruTWhpEh)pOUiFdeB!ft{OTMI#S?){n9g(TAZt5 zvSO=I$VWPwkQXLr7QMsS5`y05Ec1Bgn+#>2+yN8BicOA?FO)P~+C#xDA@C1gLg6l) z;lUy=`wo1jPNzCUp`UzP#jb2WYh~B2bV^VaWh0ua5J(d#%p5S%c;hWkpK%6F%1ckT+}p-qh>W#o!I7^CMgg98dCwXi*iR@ z59#}Olv-t({4z&)l@1(!Sscl!?J|wQZcMV_YekrZ7lU_f03z<{-mjZ;`C0^_R#LK{+!dbn3Z-}9+GsCNvj$YVjt%}G71C{3M( zu7orTb*Tl6SC?*8*mgv1Gz12>C^aky=EcaL7I2|ZUpfx|!hl>cqCSWs-4O@d zTFTNbnJMTs`kW87o@9UY4{5rkj_0ATVDLGe?M>fAM0( zB5^=Vxe znT?B#DPw%B#4~(lA~v9XobqAa*W_Un;#YmEKz>vB%u6WG^qwgQ;vPW2E9dASL`#Oq$zJ9U3G`cVPvSA|#&ZCJGY6a`ARyqMOPtNumdsFsv`< zaYA?#IR$<(BI&9CtcZy^oYxa2tBGinsI;M{*b#m*w!=SHiS01d-8T`$`09gF%Pu3V z7^QDSx8bCnG80dwr%uNisY7VB3bYm&TPE8^XIg3(>y(?3>YRTO-G{O+ YwR}Uak%U79N4FU|;^u9)>eMp-2g)P6Jpcdz diff --git a/main.c b/main.c new file mode 100644 index 0000000..613e751 --- /dev/null +++ b/main.c @@ -0,0 +1,10 @@ +#include + +int stack(void); +int list(void); + +int main(int argc, char **argv) { + stack(); + getchar(); + return 0; +} \ No newline at end of file diff --git a/stack/stack.c b/stack/stack.c index 7d22fd2a7a697900a31452eaeefe1c9cdd41b9ff..15364d1a423506b693b8038df98cc5b42fcada4b 100644 GIT binary patch literal 588 zcmb`FO>4qH6h-e=q5mO7grthvwRY1*p&K`XE=4qHf?`TCmKNz>Z+m8p`PjH}F_3w= z_r3FO^7q?Qs-w0#=%k$@dGa;VScQx>)c0Cb{n7`wBZ`p{6c6e;pFv+M1AQu^zEep3 z>{J~ss!pCBd0saho}N)!f|NJ4GN8k>^vCqfQ3ch+l$-TU&{(&p8Rx0G4>V{Ibf7;m zHEB&~lMLxlz>&EWR*omp8x`XwhYg~iyOQPQUNLig^_lO>(!7(q(URQlw~6$k?~>=$ vC9=@Gqz%|F<23VYZ)fT2M6digT@RcMn@2a@*Kc7R2AZ5)F8SL(;nMFPz|C0; literal 460 zcmb7u9nmVqf3eR%I4SFhAL`l>whrG1)qh%p$xin qw0FFy@nYp@S0#;Z9XzbcYHw(?KZUSBZg9V4w-lkRNxOa6n*9M6u8Zpc diff --git a/stack/stack.h b/stack/stack.h index d2d64ea0d27e5d4177e247c78589221aec9e4704..d06f43e50f5ad31c0ee554f10ad609ef76ae2b3c 100644 GIT binary patch literal 4426 zcmd5=$!-%t5Un#3|1c;QJ0dJ+76~CC5a5d;*T~p$Y+>w?Jq}BhUkBdncF|ou)8ny~ z1F|B|QtNxQwDafpiOgjwV_C>nCUPl-JeQ4BxL)AR7kMNzc`5hhp8KQp6!MguLUt&h z`t z#B$}lOz>m@xh3x7t2s2E89hct56t31zR3uB)Ep;rV`q&~6?iv;+!|M>xc6~etJjdG zFG^fHn_J{&W%g%CZDRHVUcBxtEDmJ=>%_@FI|RKOll!rlb<P2%Q!#1B1_Dhq0z#>GUn5iAjutc|Pz)H|z z7AjrWXN0N$I7_w9IMv4*?6U$!@N^kjZ}+5@a#jL+UE{HN(QdwSY6`h{L*{e&h3r?DEwOB0G*6vg*7_OdtDhe9as>;OyhF$LI_Sk+R|xf=B;8l{Rk>>N z(gXP{AM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B-2vGQ$*j_vNQGobbO}Y&dQ~#c6*1Vu*u~@rL^{PN8>mZ=3$5Ia6?rcy?b2%&x%t~D2 zpxbA;JB?OUj`?PMs T?tI!P6ETG-y!Gb=VdVV Date: Tue, 12 Jun 2018 17:03:31 +0800 Subject: [PATCH 16/31] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=92=8C=E4=BF=AE?= =?UTF-8?q?=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- list/list.c | Bin 2172 -> 2166 bytes list/list.h | Bin 23946 -> 24428 bytes list/list_expand.h | Bin 21118 -> 22982 bytes main.c | 4 +- tree/tree.c | 6 +- tree/tree.h | 322 +++++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 330 insertions(+), 2 deletions(-) diff --git a/list/list.c b/list/list.c index 2750dedebd3de9369e2a986d85a6b0c5823b4aba..c3b79f45cb66f0a11e1d0d032ee24ef4597381b6 100644 GIT binary patch delta 27 hcmew(@J(QY3^Sw8WO?RBM!(IAnNt~o6gO)jGXQ_S2l)U1 delta 33 kcmew+@JC>S3^Q{)L(XJb=0+f$w|PEuDkGS|%38<_0JAO$Z~y=R diff --git a/list/list.h b/list/list.h index 1de859a1637c99ec5846549e671e7ba31e0b881f..adc3808f6fc848355fea0904ee9f8fc24a2ad301 100644 GIT binary patch delta 246 zcmeC$&G=>?;|3m9MxV+2th$VTo9$UovQI8E7Gw2i$YaQv>>r`N`4i7Pes({Ge1;T; z)X5)JL^rRKImXE7H+gM@vARIM$qV!ZCYu-w ROn&7qG&#&zVRBWh0022XO>O`H delta 164 zcmaE}kFjev;|3m9=6Hsj$-Jz(Kss-;HS0N>bm-6x= fnaQ9zSuk9Fa)B(@W{pS{Ca@ac=whbHG4TQb!fh}D diff --git a/list/list_expand.h b/list/list_expand.h index 022e003ac94164e3e775cb19cd382249d9242c54..0b234a4ca9c71cea19b88402309369ae491e641e 100644 GIT binary patch delta 682 zcmZ`%&ubGw6n+z%GzpXKCe4pcRl1?6ByE%mrBtLFq}qyEcAI*TLaB(UxH+U)R_PB) z`w#T=^&p-q^bZgQJPH=ki!`1~5sxAsJqcB3H_3!NJh{$Hv71~D1RZLSizhsF@jpC1ZxN^IQ<2wx47clxoUwk+ zFP6oAE-c>McpYj-kux$lveRA&=FFt{cKh8wVR2+H2F?Uy=UNXAvja>A%cQVmBv8oc zI8GIM8&s2u*6@31khvJlU&Y?Ax-CZ_Tbq(gCztL^87qF?Wiq_+P*M6cbRs<6soAN|wRI?yj~IWYRV(cGHw(b1{A zM2&PHnzI#Hb~NaH799(A5fgC@`?k{cGH1Qi*%soxIeeK@V3b=Lcr}fi^P1o3aXE=e MQ^i45MQwiI4_r{SivR!s delta 257 zcmX@MnepEe#tnQtlY5M%COh%OvHLOPGo&!2Zr;vg&&V9lkT-chfAD56z7jBJ^M3y0 zjGQG5MGQF%sX)1Y!AO{z$u>gw;Oso%LtwU{NF|WY*}PgLl}Qk4GJ^tx7K0`bR!^SD zuR8gHsKVq);+rNLsPQrCOg<id = getId(); + p_tnode->child_num = 0; + p_tnode->father = NULL; + p_tnode->if_malloc = 0; + p_tnode->value = NULL; + p_tnode->type = NULL; + p_tnode->home = initList(); + p_tnode->room = NULL; + return p_tnode; +} + +Tree *initTree(void) { + Tree *p_tree = (Tree *)malloc(sizeof(Tree)); + p_tree->id = getId(); + p_tree->root = NULL; + return p_tree; +} + +int *initMallocValueForTNode(TNode *p_tnode, char *type, void *value) { + p_tnode->type = type; + p_tnode->value = value; + p_tnode->if_malloc = 1; + return 0; +} + +int addChildInLeft(TNode *f_tnode, TNode *c_tnode) { + Node *p_node = initNode(); + initMalllocValueForNode(p_node, "pointer", c_tnode); + insertInHead(f_tnode->home, p_node); + c_tnode->father = f_tnode; + f_tnode->child_num++; + return 0; +} + +int addChildInRight(TNode *f_tnode, TNode *c_tnode) { + Node *p_node = initNode(); + initMalllocValueForNode(p_node, "pointer", c_tnode); + insertInTail(f_tnode->home, p_node); + c_tnode->father = f_tnode; + f_tnode->child_num++; + return 0; +} + +TNode *getBrotherInLeft(TNode *p_tnode) { + List *p_home = p_tnode->father->home; + Node *p_node =p_home->head; + int index = getIndexByNode(p_home, p_node); + if (index > 0) return findByIndexForNode(p_home, index -1); + return NULL; +} + +TNode *getBrotherInRight(TNode *p_tnode) { + List *p_home = p_tnode->father->home; + Node *p_node = p_home->head; + int index = getIndexByNode(p_home, p_node); + if (index < p_home->length-1) return findByIndexForNode(p_home, index + 1); + return NULL; +} + +int removeChildInLeft(TNode *p_tnode) { + TNode *c_tnode = p_tnode->home->head; + c_tnode->father = NULL; + releaseOnlyNode(c_tnode->room); + c_tnode->room = NULL; + p_tnode->child_num--; + popFromHead(p_tnode->home); +} + +int removeChildInRight(TNode *p_tnode) { + TNode *c_tnode = p_tnode->home->tail; + c_tnode->father = NULL; + releaseOnlyNode(c_tnode->room); + c_tnode->room = NULL; + p_tnode->child_num--; + popFromTail(p_tnode->home); +} + +unsigned long long target_id = 0; +TNode *target_value_id = NULL; +TNode*_dogetChildById(char *type, void *value); + +TNode *getChildById(TNode *p_tnode, unsigned long long id) { + List *p_home = p_tnode->home; + target_id = 0; + target_value_id = NULL; + listThrough(p_home, _dogetChildById); + if (target_value_id != NULL) { + return target_value_id; + } + return NULL; +} + +TNode*_dogetChildById(char *type, void *value) { + if (!strcmp(type, "pointer")) { + TNode *p_tode = (TNode *)value; + if (p_tode->id == target_id) { + target_value_id = p_tode; + return -1; + } + } + return 0; +} + +char *target_type = NULL; +void *target_value = NULL; +TNode *target_value_value = NULL; +TNode*_dogetChildByValue(char *type, void *value); + +TNode *getChildByValue(TNode *p_tnode, char *type, void *value) { + List *p_home = p_tnode->home; + target_value = value; + target_type = type; + target_value_value = NULL; + listThrough(p_home, _dogetChildByValue); + if (target_value_value != NULL) { + return target_value_value; + } + return NULL; +} + +TNode*_dogetChildByValue(char *type, void *value) { + if (!strcmp(type, target_type)) { + TNode *p_tode = (TNode *)value; + if (!strcmp(target_value, "int")) { + if (*(int *)p_tode->value == *(int *)target_value) + { + target_value_value = p_tode; + return -1; + } + } + else if (!strcmp(target_value, "double")) + { + if (*(double *)p_tode->value == *(double *)target_value) + { + target_value_value = p_tode; + return -1; + } + } + else if (!strcmp(target_value, "string")) + { + if (!strcmp((char *)p_tode->value,(char *)target_value)) + { + target_value_value = p_tode; + return -1; + } + } + else if (!strcmp(target_value, "pointer")) + { + if (p_tode->value == target_value) + { + target_value_value = p_tode; + return -1; + } + } + + } + return 0; +} + +int removeChildById(TNode *p_tnode, unsigned long long id) { + TNode *t_tnode = getChildById(p_tnode, id); + if (t_tnode != NULL) { + TNode *p_fnode = t_tnode->father; + p_fnode->child_num--; + removeById(p_fnode->home, t_tnode->room->id); + releaseOnlyNode(t_tnode->room); + t_tnode->room = NULL; + return 0; + } + return -1; +} + +int removeChildByValue(TNode *p_tnode, char *type, void *value) { + TNode *t_tnode = getChildByValue(p_tnode, type, value); + if (t_tnode != NULL) { + TNode *p_fnode = t_tnode->father; + p_fnode->child_num--; + removeById(p_fnode->home, t_tnode->room->id); + releaseOnlyNode(t_tnode->room); + t_tnode->room = NULL; + return 0; + } + return -1; +} + +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) + { + while (p_node != NULL) { + m_index++; + p_node = p_node->next; + } + return (TNode *)p_node->value; + } + return NULL; +} + +unsigned long long getIndexByChild(TNode *f_tnode, TNode *c_tnode) { + List *p_home = f_tnode->home; + Node *p_node = p_home->head; + int m_index = 0; + while (p_node != NULL) { + TNode *p_tnode = (TNode *)p_node->value; + if (p_tnode->id == c_tnode->id) { + return m_index; + } + m_index++; + p_node = p_node->next; + } + return NULL; +} + +int removeChildByIndex(TNode *p_tnode, unsigned long long index){ + TNode *t_tnode = getChildByIndex(p_tnode, index); + if (t_tnode != NULL) { + TNode *p_fnode = t_tnode->father; + p_fnode->child_num--; + removeById(p_fnode->home, t_tnode->room->id); + releaseOnlyNode(t_tnode->room); + t_tnode->room = NULL; + return 0; + } + return -1; +} + +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 (_doTreeThroughDown(getChildByIndex(p_tnode, i), 1, func) == -1) { + break; + } + } + } + } + return 0; +} + +int _doTreeThroughUp(TNode *p_tnode, int height, int(*func)(TNode *, unsigned long long height)) { + if (p_tnode->child_num > 0) { + for (int i = 0; i < p_tnode->child_num; i++) { + if (_doTreeThroughDown(getChildByIndex(p_tnode, i), height + 1, func)) return -1; + } + } + int func_back = func(p_tnode, height); + if (func_back == -1)return -1; + return 0; +} + +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); + for (int i = 0; i < p_tnode->child_num; i++) { + if (_doTreeThroughDown(getChildByIndex(p_tnode, i), 1, func) == -1) { + break; + } + } + } + } + return 0; +} + +int _doTreeThroughDown(TNode *p_tnode, int height, int(*func)(TNode *, unsigned long long height)) { + int func_back = func(p_tnode, height); + if (p_tnode->child_num > 0) { + for (int i = 0; i < p_tnode->child_num; i++) { + if (_doTreeThroughDown(getChildByIndex(p_tnode, i), height + 1, func)) return -1; + } + } + if (func_back == -1)return -1; + return 0; +} + From 71eb84f190a376496d4b58a6f518aa2b71982f40 Mon Sep 17 00:00:00 2001 From: Saturneric Date: Tue, 12 Jun 2018 17:57:23 +0800 Subject: [PATCH 17/31] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=B8=8E=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- list/list.h | Bin 24428 -> 24778 bytes tree/tree.c | 2 +- tree/tree.h | 167 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 168 insertions(+), 1 deletion(-) diff --git a/list/list.h b/list/list.h index adc3808f6fc848355fea0904ee9f8fc24a2ad301..1e9faf6c9cc8545f3fb365f16e11ff94b73971a8 100644 GIT binary patch delta 534 zcmaE}kMYz&#tj9`>~0MC3`GonlQWsC#fupd8PXV18GM0aDL@(~r!THNS%4*gfIQda zX)H#(P(2V6HXmovW`$d!FRnOw9hbmn87?&zxZp!+(a8aP8$?m`!EE0Aldl=!#8RRC zc$`qWd6RGnGcE<2^~GaZP#rh9TiOurj6?(3$qxK1le2_`;9?J@9YwJQ$>e@**~urA zcqadnmYSR+!-qpvyrJyoc{1x5;Rd?OnZwy2e;<(Ln7lxOWAeHfp2^GPB4BcxzsoIW z;zkOP$qxgiCkyznOnxJW>^jNG_Y~t`nkIjj3!i+>muvGhr7Ik8L7=xbH)y|r2lwVg VgLVP9EHpwU%W&yzwsX{z0{~Kki);V@ delta 309 zcmX?gknznv#tj9`lMDDoCQo8c;0$I+WJqI3W$>N+kVA3u2TqR3Ml4=fME9_mZDQ48 zo$SIXH95h_W^*6cFXqV=@_dt*@NL*!z+b~WnL~kZGKcUgG`$x>I40M`a7?z7;G5jQ z%QbmHtj=aTkrHNNlu5i`o?N6RGP#GJYjTf{(BvJ4Vv{%UvrO)h5dv8~NttExJ{b)p zlm5#1Bk?vGNpG%`UB}3*$)GUVQCE6$fHFv5(`F8Z1x%B-Dd|BBNdme&VDkaxdmJDO WHXqV?!LoUWVS@n3tD6&?vg82LN@KSG diff --git a/tree/tree.c b/tree/tree.c index ca3e084..479d186 100644 --- a/tree/tree.c +++ b/tree/tree.c @@ -1,5 +1,5 @@ #include"tree.h" int tree(void) { - + return 0; } \ No newline at end of file diff --git a/tree/tree.h b/tree/tree.h index a46e524..6ceca66 100644 --- a/tree/tree.h +++ b/tree/tree.h @@ -20,6 +20,12 @@ typedef struct tree TNode *root; }Tree; +List *tree_list = NULL; +List *tnode_list = NULL; +int if_safeModeForTree = 0; +int safeModeForTree(int ifon); +int releaseAllForTree(void); + TNode *initTNode(void); Tree *initTree(void); int *initMallocValueForTNode(TNode *p_tnode, char *type, void *value); @@ -39,6 +45,36 @@ int removeChildByIndex(TNode *p_tnode, unsigned long long index); int removeChildByValue(TNode *p_tnode, char *type, void *value); int TreeThroughDown(Tree *p_tree, int(*func)(TNode *, unsigned long long height)); int TreeThroughUp(Tree *p_tree, int(*func)(TNode *, unsigned long long height)); +int TreeTravel(Tree *p_tree, int(*func)(TNode *, unsigned long long height)); + +int releaseTree(Tree *p_tree); +int releaseOnlyTree(Tree *p_tree); +int releaseTNode(TNode *p_tnode); +int releaseOnlyTNode(Tree *p_tree); + +int safeModeForTree(int ifon) { + if (ifon == 1) { + if (tnode_list == NULL && tree_list == NULL) { + tnode_list = (List *)malloc(sizeof(List)); + tree_list = (List *)malloc(sizeof(List)); + + tree_list->head = NULL; + tree_list->length = 0; + tree_list->tail = NULL; + + tnode_list->head = NULL; + tnode_list->length = 0; + tnode_list->tail = NULL; + + if_safeModeForTree = 1; + } + else { + return -1; + } + } + + return ifon; +} TNode *initTNode(void) { TNode *p_tnode = (TNode *)malloc(sizeof(TNode)); @@ -50,6 +86,21 @@ TNode *initTNode(void) { p_tnode->type = NULL; p_tnode->home = initList(); p_tnode->room = NULL; + if (if_safeModeForTree) { + if (if_safeModeForNode) { + if_safeModeForNode = 0; + Node *s_node = initNode(); + initMallocValueForTNode(s_node, "pointer", (void *)p_tnode); + insertInTail(tnode_list, s_node); + if_safeModeForNode = 1; + } + else + { + Node *s_node = initNode(); + initMallocValueForTNode(s_node, "pointer", (void *)p_tnode); + insertInTail(tnode_list, s_node); + } + } return p_tnode; } @@ -57,6 +108,21 @@ Tree *initTree(void) { Tree *p_tree = (Tree *)malloc(sizeof(Tree)); p_tree->id = getId(); p_tree->root = NULL; + if (if_safeModeForTree) { + if (if_safeModeForNode) { + if_safeModeForNode = 0; + Node *s_node = initNode(); + initMallocValueForTNode(s_node, "pointer", (void *)p_tree); + if_safeModeForNode = 1; + insertInTail(tree_list, s_node); + } + else + { + Node *s_node = initNode(); + initMallocValueForTNode(s_node, "pointer", (void *)p_tree); + insertInTail(tree_list, s_node); + } + } return p_tree; } @@ -322,3 +388,104 @@ int _doTreeThroughDown(TNode *p_tnode, int height, int(*func)(TNode *, unsigned return 0; } +int TreeTravel(Tree *p_tree, int(*func)(TNode *, unsigned long long height)) { + TNode *p_tnode = p_tree->root; + unsigned long long height = 0; + if (p_tnode != NULL) { + int func_back = func(p_tnode, height); + while (func_back > -2) { + if (func_back > -1) { + p_tnode = getChildByIndex(func_back,func_back); + func(p_tnode, height + 1); + } + else + { + p_tnode = p_tnode->father; + func(p_tnode, height - 1); + + } + } + } + return 0; +} +int releaseTNode(TNode *p_tnode) { + if(p_tnode->child_num == 0){ + releaseList(p_tnode->home); + if (p_tnode->father != NULL) { + removeChildById(p_tnode->father, p_tnode->id); + } + if (strcmp(p_tnode->type, "pointer")) { + if (!strcmp(p_tnode->type, "list")) { + releaseList((List *)p_tnode->value); + } + else { + free(p_tnode->value); + } + } + p_tnode->value = NULL; + p_tnode->type = NULL; + p_tnode->id = 0; + p_tnode->if_malloc = 0; + free(p_tnode); + } + return 0; +} + +int _doreleaseTree(TNode *p_tnode, int height); + +int releaseTree(Tree *p_tree) { + TreeThroughUp(p_tree, _doreleaseTree); + p_tree->root = NULL; + p_tree->id = 0; + free(p_tree); +} + +int _doreleaseTree(TNode *p_tnode, int height) { + releaseTNode(p_tnode); + return 0; +} + + +int releaseOnlyTree(Tree *p_tree) { + p_tree->id = 0; + p_tree->root = NULL; + free(p_tree); + return 0; +} + +int releaseOnlyTNode(TNode *p_tnode) { + releaseList(p_tnode->home); + if (strcmp(p_tnode->type, "pointer")) { + if (!strcmp(p_tnode->type, "list")) { + releaseList((List *)p_tnode->value); + } + else { + free(p_tnode->value); + } + } + p_tnode->value = NULL; + p_tnode->type = NULL; + p_tnode->id = 0; + p_tnode->if_malloc = 0; + free(p_tnode); + return 0; +} + +int releaseAllForTree(void) { + if (if_safeModeForTree) { + if_safeModeForTree = 0; + Node *p_node = tnode_list->head; + while (p_node != NULL) { + TNode *p_tnode = (TNode *)p_node->value; + releaseOnlyTNode(p_tnode); + } + Node *p_node = tree_list->head; + while (p_node != NULL) { + Tree *p_tree = (Tree *)p_node->value; + releaseOnlyTree(p_tree); + } + releaseList(tnode_list); + releaseList(tree_list); + } + return 0; +} \ No newline at end of file From 6dbd74f199546ecd05c32c89a4572121b8b5abde Mon Sep 17 00:00:00 2001 From: Saturneric Date: Tue, 12 Jun 2018 19:07:12 +0800 Subject: [PATCH 18/31] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- list/list.c | Bin 2166 -> 20414 bytes list/list.h | Bin 24778 -> 3888 bytes list/list_expand.c | 328 +++++++++++++++++++++++++++++++ list/list_expand.h | Bin 22982 -> 3374 bytes main.c | 12 -- stack/stack.c | Bin 588 -> 2886 bytes stack/stack.h | Bin 4426 -> 1276 bytes stack/stack_expand.c | 51 +++++ stack/stack_expand.h | Bin 3760 -> 838 bytes test.c | 63 ++++++ test.h | 15 ++ tree/tree.c | 439 ++++++++++++++++++++++++++++++++++++++++- tree/tree.h | 458 ++----------------------------------------- 13 files changed, 911 insertions(+), 455 deletions(-) create mode 100644 list/list_expand.c delete mode 100644 main.c create mode 100644 stack/stack_expand.c create mode 100644 test.c create mode 100644 test.h diff --git a/list/list.c b/list/list.c index c3b79f45cb66f0a11e1d0d032ee24ef4597381b6..e434c5a7b85155ae381b82bd6411fdc32bc6d9ba 100644 GIT binary patch literal 20414 zcmeHP%Who95$$Cd!2d92kYFfTp%o+uoEKmNF)To45Ll6y0!57^CZpki98qy(En;L7 z7=f4mmV80JAgiqN1zG1&r)$nsb#>pzNR-Uj!hqz=y;arquIjqY`R{-B)0H%lpI7^O zBYiusI!U+E!*ra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as;xC*y z0x^85h;Em})9t(@K8=!m_mA;N<;PZee&?xO26guGCdu&9JzrA~uW{5Pl~LBCEWXFKzPn$mQmPQ$+kticYPdj(20l9fUayR1+In-jtGKj_$A>%GoUDuY;T*8^21{(f^_qb6OuT<+WC zrSWOI4BMB;OR?usPDGQRHKj9L9g~^jn8T-1#EhLS{TRQ@1D8W!OyzR1Lv1i z@$K0()|oTP>oD(eyieyxEJ^b*n#XiLY8A26sflm;HpMr)P;l6r64U&qqrE-nb!U!K z8|?hBNt4emWsaB^*{!Kv`qsoS)2pZ+lcx=~wp$Sl{vw? Kd&sP)cK-!hHOkun diff --git a/list/list_expand.c b/list/list_expand.c new file mode 100644 index 0000000..a5f8fb3 --- /dev/null +++ b/list/list_expand.c @@ -0,0 +1,328 @@ +#include "list_expand.h" + +Node *nodeWithInt(int m_int) { + int *p_int = (int *)malloc(sizeof(int)); + *p_int = m_int; + Node *p_node = initNode(); + initMallocValueForNode(p_node, "int", (void *)p_int); + return p_node; +} + +Node *nodeWithDouble(double m_double) { + double *p_double = (double *)malloc(sizeof(double)); + *p_double = m_double; + Node *p_node = initNode(); + initMallocValueForNode(p_node, "double", (void *)p_double); + return p_node; +} + +Node *nodeWithString(const char *m_string) { + char *p_string = (char *)malloc(sizeof(char)*(strlen(m_string) + 1)); + strcpy_s(p_string, sizeof(p_string), m_string); + Node *p_node = initNode(); + initMallocValueForNode(p_node, "string", (void *)p_string); + return p_node; +} + +Node *nodeWithPointer(void *m_pointer) { + Node *p_node = initNode(); + initMallocValueForNode(p_node, "pointer", m_pointer); + return p_node; +} + +Node *nodeWithComplex(void) { + Node *p_node = initNode(); + p_node->type = "list"; + p_node->value = initList(); + p_node->if_malloc = 1; + return p_node; +} + +Node *findByIndexForNode(List *p_list, unsigned long long m_index) { + Node *p_node = p_list->head; + for (unsigned long long i = 0; i < m_index; i++) { + p_node = p_node->next; + } + return p_node; +} + +int listThrough(List *p_list, int(*p_func)(const char *, void *)) { + Node *p_node = p_list->head; + while (p_node != NULL) { + if (p_node->if_malloc == 1) { + int m_return = (*p_func)(p_node->type, p_node->value); + if (m_return == -1) break; + else if (m_return == 1) { + p_node = p_node->last; + continue; + } + else { + + } + } + p_node = p_node->next; + } + return 0; +} + +int getByIntForNode(Node *p_node) { + if (!strcmp(p_node->type, "int")) return *(int *)(p_node->value); + else return -1; +} + +char *getByStringForNode(Node *p_node) { + if (!strcmp(p_node->type, "string")) return (char *)(p_node->value); + else return NULL; +} + +double getByDoubleForNode(Node *p_node) { + if (!strcmp(p_node->type, "double")) return *(double *)(p_node->value); + else return -1; +} + +void *getByPointerForNode(Node *p_node) { + if (!strcmp(p_node->type, "pointer")) return (void *)(p_node->value); + else return NULL; +} + +void printListInfo(List *p_list, int priority) { + for (int i = 0; i < priority; i++) printf(" "); + printf("###LIST(location:%p, id:%llu){\n", p_list, p_list->id); + for (int i = 0; i < priority + 1; i++) printf(" "); + printf("HEAD->%p / Tail->%p / Length:%llu\n", p_list->head, p_list->tail, p_list->length); + Node *p_node = p_list->head; + int i = 0; + while (p_node != NULL) { + for (int i = 0; i < priority + 1; i++) printf(" "); + printf("%d.... \n", i); + printNodeInfo(p_node, priority + 1); + p_node = p_node->next; + i++; + } + for (int i = 0; i < priority; i++) printf(" "); + printf("}\n"); + +} + +void printList(List *p_list) { + Node *p_node = p_list->head; + printf("["); + int if_nearLast = 0; + while (p_node != NULL) { + if (!if_nearLast && p_node->next == NULL) if_nearLast = 1; + if (!strcmp(p_node->type, "int")) { + printf("%d", *(int *)(p_node->value)); + } + else if (!strcmp(p_node->type, "double")) { + printf("%a", *(double *)(p_node->value)); + } + else if (!strcmp(p_node->type, "string")) { + printf("%s", (char *)(p_node->value)); + } + else if (!strcmp(p_node->type, "pointer")) { + printf("%s", (char *)(p_node->value)); + } + else if (!strcmp(p_node->type, "list")) { + printList((List *)p_node->value); + } + if (!if_nearLast) { + printf(", "); + } + p_node = p_node->next; + } + printf("]"); +} + +void printNodeInfo(Node *p_node, int priority) { + for (int i = 0; i < priority; i++) printf(" "); + printf("#NODE(location:%p, id:%llu){\n", p_node, p_node->id); + for (int i = 0; i < priority + 1; i++) printf(" "); + 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)); + } + 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)); + } + 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)); + } + 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)); + } + else if (!strcmp(p_node->type, "list")) { + for (int i = 0; i < priority + 1; i++) printf(" "); + printf("VALUE(List):\n"); + printListInfo((List *)p_node->value, priority + 2); + } + for (int i = 0; i < priority; i++) printf(" "); + printf("}\n"); +} + +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("}\n"); +} + + +Node *findByIntForNode(List *p_list, int target) { + int *p_target = (int *)malloc(sizeof(int)); + *p_target = target; + Node *t_node = findByValue(p_list, "int", p_target); + free(p_target); + return t_node; +} + +Node *findByDoubleForNode(List *p_list, double target) { + double *p_target = (double *)malloc(sizeof(double)); + *p_target = target; + Node *t_node = findByValue(p_list, "double", p_target); + free(p_target); + return t_node; +} + +Node *findByStringForNode(List *p_list, char *target) { + char *p_temp = (char *)malloc(sizeof(char)*(strlen(target) + 1)); + strcpy_s(p_temp, sizeof(p_temp), target); + Node *t_node = findByValue(p_list, "string", p_temp); + free(p_temp); + return t_node; +} + +Node *findByPointerForNode(List *p_list, void *target) { + Node *t_node = findByValue(p_list, "pointer", target); + return t_node; +} + +int addValueForComplex(Node * p_node, char *type, void *value) { + if (!strcmp(p_node->type, "list")) { + List *c_list = (List *)p_node->value; + Node *c_node = initNode(); + initMallocValueForNode(c_node, type, value); + insertInTail(c_list, c_node); + return 0; + } + return -1; +} + +int addIntForComplex(Node *p_node, int temp) { + if (!strcmp(p_node->type, "list")) { + int *p_temp = (int *)malloc(sizeof(int)); + *p_temp = temp; + addValueForComplex(p_node, "int", p_temp); + return 0; + } + return -1; +} + +int addDoubleForComplex(Node *p_node, double temp) { + if (!strcmp(p_node->type, "list")) { + double *p_temp = (double *)malloc(sizeof(double)); + *p_temp = temp; + addValueForComplex(p_node, "double", p_temp); + return 0; + } + return -1; +} + +int addStringForComplex(Node *p_node, char *temp) { + if (!strcmp(p_node->type, "list")) { + char *p_temp = (char *)malloc(sizeof(strlen(temp) + 1)); + strcpy_s(p_temp, sizeof(p_temp), temp); + addValueForComplex(p_node, "string", p_temp); + return 0; + } + return -1; +} + +int addPointerForComplex(Node *p_node, void *temp) { + if (!strcmp(p_node->type, "list")) { + addValueForComplex(p_node, "pointer", temp); + return 0; + } + return -1; +} + +List *m_findByInt(List* p_list, int temp) { + int *p_temp = (int *)malloc(sizeof(int)); + *p_temp = temp; + List *t_list = mply_findByValue(p_list, "int", (void *)p_temp); + free(p_temp); + return t_list; +} + +List *m_findByDouble(List* p_list, double temp) { + double *p_temp = (double *)malloc(sizeof(double)); + *p_temp = temp; + List *t_list = mply_findByValue(p_list, "double", (void *)p_temp); + free(p_temp); + return t_list; +} + +List *m_findByString(List* p_list, char *temp) { + char *p_temp = (char *)malloc(sizeof(char)*(strlen(temp) + 1)); + strcpy_s(p_temp, sizeof(p_temp), temp); + List *t_list = mply_findByValue(p_list, "string", (void *)p_temp); + free(p_temp); + return t_list; +} + +List *m_findByPointer(List* p_list, void *temp) { + List *t_list = mply_findByValue(p_list, "double", (void *)temp); + return t_list; +} + +unsigned long long getIndexByNode(List *p_list, Node *p_node) { + Node *t_node = p_list->head; + unsigned long long index = 0; + while (t_node != NULL) { + if (p_node->id == t_node->id) return index; + index++; + t_node = t_node->next; + } + return 0; +} + +List *m_findByIntForNode(List* p_list, int temp) { + int *p_temp = (int *)malloc(sizeof(int)); + *p_temp = temp; + return mply_findByValue(p_list, "int", (void *)p_temp); +} + +List *m_findByDoubleForNode(List* p_list, double temp) { + double *p_temp = (double *)malloc(sizeof(double)); + *p_temp = temp; + return mply_findByValue(p_list, "double", (void *)p_temp); +} + +List *m_findByStringForNode(List* p_list, char *temp) { + char *p_temp = (char *)malloc(sizeof(char) * (strlen(temp) + 1)); + strcpy_s(p_temp, sizeof(p_temp), temp); + return mply_findByValue(p_list, "string", (void *)p_temp); +} + +List *m_findByPointerForNode(List* p_list, void *temp) { + return mply_findByValue(p_list, "pointer", (void *)temp); +} diff --git a/list/list_expand.h b/list/list_expand.h index 0b234a4ca9c71cea19b88402309369ae491e641e..e2f32e93f8cb09789ef0ab4230bd9d77b18a929c 100644 GIT binary patch delta 20 ccmX@MnQ@)ehDAJ+7YT?>Uc-|%d0V6a0A1e*UjP6A literal 22982 zcmdU1-)~%35k4vs#YlODC&VUJt96o=l()745pb(o#EzRy`a>x-&U#~8Bpc&jB!m_z zicqA2RHRBsNJzX?;)Oqee}D)019;{EUXXa=4bd{+o&EOAoO|}}-RoT^mX)r(_uMmc zX1bNK%Ee|2$n+?IPKXA?4!3I9p)ri z%+-^Z!=+!*c&QeN^`u%$H(jg8WIegollA4MxV=@x!bbS6Urr zQ3w_@A8R{GiUZr23$`qi%tt+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mvK_pU3~4DH{=R0d2vQpVSGXGV>6U9nqZSC)FvR{Cl` z+Nv|Us{2uSpQdA~8JZnk=4m+zwCk+>Yc+eiy=?1qwU=!@q#e^epB;0wn#q}R?~+I9 z`3gF_%4y?eI+>tcOP|(!;A?C(R_fH#>DzLA)J5d@4B+dc^=z6k>%9xCZ$_a8>YKlH z|IaZvv(3K0<}da$?72=mrrbleRTd}d(zlxHtpF8Db=NA#U1WNy-OEqk`^cSYhkjfY z&on{?o^#mQcnvG}{)xJ&cW}-%eiz??!1s1W)_5$=1YOcRt?S$vqF`>7r zBL@28Y->blv>mVIDq3?M#Q#SQCDJ;|hiDCN`QzX^^(?$t>O<7Cv&|8CYx@y-o2O%% z@RZ}Szty!q7pdn3%N|Dc?{mzb)m@*0anBMFZ?8{_M?e8^W#~4eEB=2MxmB - -int stack(void); -int list(void); -int tree(void); - -int main(int argc, char **argv) { - list(); - tree(); - getchar(); - return 0; -} \ No newline at end of file diff --git a/stack/stack.c b/stack/stack.c index 15364d1a423506b693b8038df98cc5b42fcada4b..32742ca3a3c9f2e20eb15cc713ab17597f1e3489 100644 GIT binary patch literal 2886 zcmbVO%We}v5bUdw_y+?Q8xaI&1V`7E@69xsMWUWZU|!{)Hg%k9Ia5`gg*(6Ol`?@wRGq0-n30u4wM<~yVj3vRsTVQK zxzyRFU9?5~YpB||%V$oC<}>(=G2pq%?Yc1Gc!SfpO0z4@?2(cwVlvDhbEcJ~e(YGy zHO^3qG$*3XFJi2A8fh6AIu+?LBz04Cn2ejixFO+dk2vve-@$PcsxakQg!|~N9b}R5 zn3FxvbE5C7_sTK99I?ew@j5fo{I=()gtB9F@5bEZh?SLiMY~irHS4r9lmUyq4jQ~D zCY;s!znx<^4qH6h-e=q5mO7grthvwRY1*p&K`XE=4qHf?`TCmKNz>Z+m8p`PjH}F_3w= z_r3FO^7q?Qs-w0#=%k$@dGa;VScQx>)c0Cb{n7`wBZ`p{6c6e;pFv+M1AQu^zEep3 z>{J~ss!pCBd0saho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z{W z$JSxMD(&F7Q_}gata+TtP#&o?gSbD#4ovfD@^I{a4qkkHwXqXNr@sl?v~t;{`E=z+ z&sqP&uNFIdx-*jQyt<}ER`2YDsB5J>hI^}Nu?{EaFqKa*9XNA%$|>YAey!R6P0VnA Jiszi*e*tWWm}LL} diff --git a/stack/stack_expand.c b/stack/stack_expand.c new file mode 100644 index 0000000..faea8b1 --- /dev/null +++ b/stack/stack_expand.c @@ -0,0 +1,51 @@ +#include "stack_expand.h" + +SNode *snodeWithInt(int temp) { + SNode *p_snode = initSNode(); + int *p_temp = (int *)malloc(sizeof(int)); + *p_temp = temp; + initMallocValueForSNode(p_snode, "int", p_temp); + return p_snode; +} + +SNode *snodeWithDouble(double temp) { + SNode *p_snode = initSNode(); + double *p_temp = (double *)malloc(sizeof(double)); + *p_temp = temp; + initMallocValueForSNode(p_snode, "double", p_temp); + return p_snode; +} + +SNode *snodeWithString(char *temp) { + SNode *p_snode = initSNode(); + char *p_temp = (char *)malloc(sizeof(char)*(strlen(temp) + 1)); + strcpy_s(p_temp, strlen(p_temp), temp); + initMallocValueForSNode(p_snode, "string", p_temp); + return p_snode; +} + +SNode *snodeWithPointer(void *temp) { + SNode *p_snode = initSNode(); + initMallocValueForSNode(p_snode, "pointer", temp); + return p_snode; +} + +int getValueByIntForSNode(SNode *p_snode) { + if (!strcmp(p_snode->type, "int")) return *(int *)p_snode->value; + else return -1; +} + +double getValueByDoubleForSNode(SNode *p_snode) { + if (!strcmp(p_snode->type, "double")) return *(double *)p_snode->value; + else return -1; +} + +char *getValueByStringForSNode(SNode *p_snode) { + if (!strcmp(p_snode->type, "int")) return (char *)p_snode->value; + else return NULL; +} + +void *getValueByPointerForSNode(SNode *p_snode) { + if (!strcmp(p_snode->type, "int")) return (void *)p_snode->value; + else return NULL; +} \ No newline at end of file diff --git a/stack/stack_expand.h b/stack/stack_expand.h index fe14aa2a308bec03fba7bd35e52a8e355c9664d1..300b68efb06b1eb147a2e3b461a5e23cdbe412f2 100644 GIT binary patch delta 11 ScmdlWdyH)Z5A){4eJ zY!B&IJRZ_#51;T7ukjvzyumjd@U)Lzp5B$dy`|(LIb3HiF?#fHTISqkCe!ltm6;dJ zdXK*p$Xp!-I(X_LUH8;3y)5ya{TT7tT%DSF=&9~y?9BuNb~8b@aSjKJDxD~p!<<>1 zxpQuONC&)4f-&t1d|@1!;s~#BURM8>PtH}RGWA_&r0cBrr~A^>tFFB+N8PEWK6NkZ zeA?bM^?GwWC2l$=m~pBX4p|B3BOi;f88IHQncz7sWNw1dXqm0B5xj)ib{V0+ishdV znD!GqadSWBq=&@Hf}Vd71E=I&uRj%2qFODit_I|8hKX9mGr<O&g%A{A?%HIQQ zF70(JsFp;j!&8q_3~vkn8>;M{Xa`mM_>2$yRFT#0&D2h_9b|ca)nm#k=Vm*#<#t|9 izRSDe6XMEmFaIXl=f6M6{{eL>=dPRZ-!84>j{X+}L{?=0 diff --git a/test.c b/test.c new file mode 100644 index 0000000..c21a0f5 --- /dev/null +++ b/test.c @@ -0,0 +1,63 @@ +#include "test.h" + +int list(void) { + init_rand(); + safeModeForNode(1); + List *t_list = initList(); + + /*for(int i = 0; i < 9; i++){ + Node *t_node = initNode(); + int *t_i = (int *)malloc(sizeof(int)); + *t_i = i; + initMallocValue(t_node,"int",(void *)t_i); + insertInTail(t_list,t_node); + }*/ + + /*Node *t_node = initNode(); + insertInTail(t_list,t_node); + initMalllocValue(t_node,(void *)"there");*/ + + for (int i = 0; i < 12; i++) { + insertInHead(t_list, nodeWithInt(i)); + insertInTail(t_list, nodeWithInt(i)); + } + + + + printListInfo(t_list, 0); + printList(t_list); + List *m_list; + m_list = m_findByIntForNode(t_list, 5); + printList(m_list); + printf("\n"); + + releaseAllForNode(); + + return 0; +} + +int tree(void) { + safeModeForTree(1); + Tree *t_tree = initTree(); + releaseAllForTree(); + return 0; +} + +int stack(void) { + Stack *t_stack = initStack(); + for (int i = 0; i < 10; i++) { + pushStack(t_stack, snodeWithInt(i)); + } + for (int i = 0; i < 10; i++) { + printf("%d", getValueByIntForSNode(popStack(t_stack))); + } + releaseStack(t_stack); + return 0; +} + + +int main(int argc, char **argv) { + tree(); + getchar(); + return 0; +} \ No newline at end of file diff --git a/test.h b/test.h new file mode 100644 index 0000000..cba9876 --- /dev/null +++ b/test.h @@ -0,0 +1,15 @@ +#ifndef TEST_H +#define TEST_H + +#include + +#include "list/list_expand.h" +#include "stack/stack_expand.h" +#include "tree/tree.h" + +int stack(void); +int list(void); +int tree(void); + +#endif // TEST_H + diff --git a/tree/tree.c b/tree/tree.c index 479d186..8d981e8 100644 --- a/tree/tree.c +++ b/tree/tree.c @@ -1,5 +1,438 @@ #include"tree.h" -int tree(void) { - + +int safeModeForTree(int ifon) { + if (ifon == 1) { + if (tnode_list == NULL && tree_list == NULL) { + tnode_list = (List *)malloc(sizeof(List)); + tree_list = (List *)malloc(sizeof(List)); + + tree_list->head = NULL; + tree_list->length = 0; + tree_list->tail = NULL; + + tnode_list->head = NULL; + tnode_list->length = 0; + tnode_list->tail = NULL; + + if_safeModeForTree = 1; + } + else { + return -1; + } + } + + return ifon; +} + +TNode *initTNode(void) { + TNode *p_tnode = (TNode *)malloc(sizeof(TNode)); + p_tnode->id = getId(); + p_tnode->child_num = 0; + p_tnode->father = NULL; + p_tnode->if_malloc = 0; + p_tnode->value = NULL; + p_tnode->type = NULL; + p_tnode->home = initList(); + p_tnode->room = NULL; + if (if_safeModeForTree) { + if (if_safeModeForNode) { + if_safeModeForNode = 0; + Node *s_node = initNode(); + initMallocValueForNode(s_node, "pointer", (void *)p_tnode); + insertInTail(tnode_list, s_node); + if_safeModeForNode = 1; + } + else + { + Node *s_node = initNode(); + initMallocValueForNode(s_node, "pointer", (void *)p_tnode); + insertInTail(tnode_list, s_node); + } + } + return p_tnode; +} + +Tree *initTree(void) { + Tree *p_tree = (Tree *)malloc(sizeof(Tree)); + p_tree->id = getId(); + p_tree->root = NULL; + if (if_safeModeForTree) { + if (if_safeModeForNode) { + if_safeModeForNode = 0; + Node *s_node = initNode(); + initMallocValueForNode(s_node, "pointer", (void *)p_tree); + if_safeModeForNode = 1; + insertInTail(tree_list, s_node); + } + else + { + Node *s_node = initNode(); + initMallocValueForNode(s_node, "pointer", (void *)p_tree); + insertInTail(tree_list, s_node); + } + } + return p_tree; +} + +int *initMallocValueForTNode(TNode *p_tnode, char *type, void *value) { + p_tnode->type = type; + p_tnode->value = value; + p_tnode->if_malloc = 1; return 0; -} \ No newline at end of file +} + +int addChildInLeft(TNode *f_tnode, TNode *c_tnode) { + Node *p_node = initNode(); + initMallocValueForNode(p_node, "pointer", c_tnode); + insertInHead(f_tnode->home, p_node); + c_tnode->father = f_tnode; + f_tnode->child_num++; + return 0; +} + +int addChildInRight(TNode *f_tnode, TNode *c_tnode) { + Node *p_node = initNode(); + initMallocValueForNode(p_node, "pointer", c_tnode); + insertInTail(f_tnode->home, p_node); + c_tnode->father = f_tnode; + f_tnode->child_num++; + return 0; +} + +TNode *getBrotherInLeft(TNode *p_tnode) { + List *p_home = p_tnode->father->home; + Node *p_node = p_home->head; + unsigned long long index = getIndexByNode(p_home, p_node); + if (index > 0) return (TNode *)(findByIndexForNode(p_home, index - 1)->value); + return NULL; +} + +TNode *getBrotherInRight(TNode *p_tnode) { + List *p_home = p_tnode->father->home; + Node *p_node = p_home->head; + unsigned long long index = getIndexByNode(p_home, p_node); + if (index < p_home->length - 1) return (TNode *)(findByIndexForNode(p_home, index + 1)->value); + return NULL; +} + +int removeChildInLeft(TNode *p_tnode) { + TNode *c_tnode = (TNode *)p_tnode->home->head->value; + c_tnode->father = NULL; + releaseOnlyNode(c_tnode->room); + c_tnode->room = NULL; + p_tnode->child_num--; + popFromHead(p_tnode->home); + return 0; +} + +int removeChildInRight(TNode *p_tnode) { + TNode *c_tnode = (TNode *)p_tnode->home->tail->value; + c_tnode->father = NULL; + releaseOnlyNode(c_tnode->room); + c_tnode->room = NULL; + p_tnode->child_num--; + popFromTail(p_tnode->home); + return 0; +} + + +TNode *getChildById(TNode *p_tnode, unsigned long long id) { + List *p_home = p_tnode->home; + target_id = 0; + target_value_id = NULL; + listThrough(p_home, _dogetChildById); + if (target_value_id != NULL) { + return target_value_id; + } + return NULL; +} + +int _dogetChildById(const char *type, void *value) { + if (!strcmp(type, "pointer")) { + TNode *p_tode = (TNode *)value; + if (p_tode->id == target_id) { + target_value_id = p_tode; + return -1; + } + } + return 0; +} + +char *target_type = NULL; +void *target_value = NULL; +TNode *target_value_value = NULL; +int _dogetChildByValue(const char *type, void *value); + +TNode *getChildByValue(TNode *p_tnode, char *type, void *value) { + List *p_home = p_tnode->home; + target_value = value; + target_type = type; + target_value_value = NULL; + listThrough(p_home, _dogetChildByValue); + if (target_value_value != NULL) { + return target_value_value; + } + return NULL; +} + +int _dogetChildByValue(const char *type, void *value) { + if (!strcmp(type, target_type)) { + TNode *p_tode = (TNode *)value; + if (!strcmp(target_value, "int")) { + if (*(int *)p_tode->value == *(int *)target_value) + { + target_value_value = p_tode; + return -1; + } + } + else if (!strcmp(target_value, "double")) + { + if (*(double *)p_tode->value == *(double *)target_value) + { + target_value_value = p_tode; + return -1; + } + } + else if (!strcmp(target_value, "string")) + { + if (!strcmp((char *)p_tode->value, (char *)target_value)) + { + target_value_value = p_tode; + return -1; + } + } + else if (!strcmp(target_value, "pointer")) + { + if (p_tode->value == target_value) + { + target_value_value = p_tode; + return -1; + } + } + + } + return 0; +} + +int removeChildById(TNode *p_tnode, unsigned long long id) { + TNode *t_tnode = getChildById(p_tnode, id); + if (t_tnode != NULL) { + TNode *p_fnode = t_tnode->father; + p_fnode->child_num--; + removeById(p_fnode->home, t_tnode->room->id); + releaseOnlyNode(t_tnode->room); + t_tnode->room = NULL; + return 0; + } + return -1; +} + +int removeChildByValue(TNode *p_tnode, char *type, void *value) { + TNode *t_tnode = getChildByValue(p_tnode, type, value); + if (t_tnode != NULL) { + TNode *p_fnode = t_tnode->father; + p_fnode->child_num--; + removeById(p_fnode->home, t_tnode->room->id); + releaseOnlyNode(t_tnode->room); + t_tnode->room = NULL; + return 0; + } + return -1; +} + +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) + { + while (p_node != NULL) { + m_index++; + p_node = p_node->next; + } + return (TNode *)p_node->value; + } + return NULL; +} + +unsigned long long getIndexByChild(TNode *f_tnode, TNode *c_tnode) { + List *p_home = f_tnode->home; + Node *p_node = p_home->head; + int m_index = 0; + while (p_node != NULL) { + TNode *p_tnode = (TNode *)p_node->value; + if (p_tnode->id == c_tnode->id) { + return m_index; + } + m_index++; + p_node = p_node->next; + } + return -1; +} + +int removeChildByIndex(TNode *p_tnode, unsigned long long index) { + TNode *t_tnode = getChildByIndex(p_tnode, index); + if (t_tnode != NULL) { + TNode *p_fnode = t_tnode->father; + p_fnode->child_num--; + removeById(p_fnode->home, t_tnode->room->id); + releaseOnlyNode(t_tnode->room); + t_tnode->room = NULL; + return 0; + } + return -1; +} + + +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) { + break; + } + } + } + } + return 0; +} + +int _doTreeThroughUp(TNode *p_tnode, int height, int(*func)(TNode *, unsigned long long height)) { + if (p_tnode->child_num > 0) { + for (int i = 0; i < p_tnode->child_num; i++) { + if (_doTreeThroughUp(getChildByIndex(p_tnode, i), height + 1, func)) return -1; + } + } + int func_back = func(p_tnode, height); + if (func_back == -1)return -1; + return 0; +} + + +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); + for (int i = 0; i < p_tnode->child_num; i++) { + if (_doTreeThroughDown(getChildByIndex(p_tnode, i), 1, func) == -1) { + break; + } + } + } + } + return 0; +} + +int _doTreeThroughDown(TNode *p_tnode, int height, int(*func)(TNode *, unsigned long long height)) { + int func_back = func(p_tnode, height); + if (p_tnode->child_num > 0) { + for (int i = 0; i < p_tnode->child_num; i++) { + if (_doTreeThroughDown(getChildByIndex(p_tnode, i), height + 1, func)) return -1; + } + } + if (func_back == -1)return -1; + return 0; +} + +int TreeTravel(Tree *p_tree, int(*func)(TNode *, unsigned long long height)) { + TNode *p_tnode = p_tree->root; + unsigned long long height = 0; + if (p_tnode != NULL) { + int func_back = func(p_tnode, height); + while (func_back > -2) { + if (func_back > -1) { + p_tnode = getChildByIndex(p_tnode, func_back); + func(p_tnode, height + 1); + } + else + { + p_tnode = p_tnode->father; + func(p_tnode, height - 1); + + } + } + } + return 0; +} +int releaseTNode(TNode *p_tnode) { + if (p_tnode->child_num == 0) { + releaseList(p_tnode->home); + if (p_tnode->father != NULL) { + removeChildById(p_tnode->father, p_tnode->id); + } + if (strcmp(p_tnode->type, "pointer")) { + if (!strcmp(p_tnode->type, "list")) { + releaseList((List *)p_tnode->value); + } + else { + free(p_tnode->value); + } + } + p_tnode->value = NULL; + p_tnode->type = NULL; + p_tnode->id = 0; + p_tnode->if_malloc = 0; + free(p_tnode); + } + return 0; +} + +int releaseTree(Tree *p_tree) { + TreeThroughUp(p_tree, _doreleaseTree); + p_tree->root = NULL; + p_tree->id = 0; + free(p_tree); + return 0; +} + +int _doreleaseTree(TNode *p_tnode, unsigned long long height) { + releaseTNode(p_tnode); + return 0; +} + +int releaseOnlyTree(Tree *p_tree) { + p_tree->id = 0; + p_tree->root = NULL; + free(p_tree); + return 0; +} + +int releaseOnlyTNode(TNode *p_tnode) { + releaseList(p_tnode->home); + if (strcmp(p_tnode->type, "pointer")) { + if (!strcmp(p_tnode->type, "list")) { + releaseList((List *)p_tnode->value); + } + else { + free(p_tnode->value); + } + } + p_tnode->value = NULL; + p_tnode->type = NULL; + p_tnode->id = 0; + p_tnode->if_malloc = 0; + free(p_tnode); + return 0; +} + +int releaseAllForTree(void) { + if (if_safeModeForTree) { + if_safeModeForTree = 0; + Node *p_node = tnode_list->head; + while (p_node != NULL) { + TNode *p_tnode = (TNode *)p_node->value; + releaseOnlyTNode(p_tnode); + } + p_node = tree_list->head; + while (p_node != NULL) { + Tree *p_tree = (Tree *)p_node->value; + releaseOnlyTree(p_tree); + } + releaseList(tnode_list); + releaseList(tree_list); + } + return 0; +} diff --git a/tree/tree.h b/tree/tree.h index 6ceca66..3f5a7ae 100644 --- a/tree/tree.h +++ b/tree/tree.h @@ -1,6 +1,6 @@ -#pragma once - #include "../list/list_expand.h" +#ifndef TREE_H +#define TREE_H typedef struct tree_node { @@ -20,9 +20,9 @@ typedef struct tree TNode *root; }Tree; -List *tree_list = NULL; -List *tnode_list = NULL; -int if_safeModeForTree = 0; +List *tree_list; +List *tnode_list; +int if_safeModeForTree; int safeModeForTree(int ifon); int releaseAllForTree(void); @@ -47,445 +47,23 @@ int TreeThroughDown(Tree *p_tree, int(*func)(TNode *, unsigned long long height) int TreeThroughUp(Tree *p_tree, int(*func)(TNode *, unsigned long long height)); int TreeTravel(Tree *p_tree, int(*func)(TNode *, unsigned long long height)); +int _dogetChildById(const char *type, void *value); +int _dogetChildByValue(const char *type, void *value); +int _doreleaseTree(TNode *p_tnode, unsigned long long height); +int _doTreeThroughDown(TNode *p_tnode, int height, int(*func)(TNode *, unsigned long long height)); +int _doTreeThroughUp(TNode *p_tnode, int height, int(*func)(TNode *, unsigned long long height)); + int releaseTree(Tree *p_tree); int releaseOnlyTree(Tree *p_tree); int releaseTNode(TNode *p_tnode); -int releaseOnlyTNode(Tree *p_tree); +int releaseOnlyTNode(TNode *p_tnode); -int safeModeForTree(int ifon) { - if (ifon == 1) { - if (tnode_list == NULL && tree_list == NULL) { - tnode_list = (List *)malloc(sizeof(List)); - tree_list = (List *)malloc(sizeof(List)); +char *target_type; +void *target_value; +TNode *target_value_value; - tree_list->head = NULL; - tree_list->length = 0; - tree_list->tail = NULL; - - tnode_list->head = NULL; - tnode_list->length = 0; - tnode_list->tail = NULL; - - if_safeModeForTree = 1; - } - else { - return -1; - } - } - - return ifon; -} - -TNode *initTNode(void) { - TNode *p_tnode = (TNode *)malloc(sizeof(TNode)); - p_tnode->id = getId(); - p_tnode->child_num = 0; - p_tnode->father = NULL; - p_tnode->if_malloc = 0; - p_tnode->value = NULL; - p_tnode->type = NULL; - p_tnode->home = initList(); - p_tnode->room = NULL; - if (if_safeModeForTree) { - if (if_safeModeForNode) { - if_safeModeForNode = 0; - Node *s_node = initNode(); - initMallocValueForTNode(s_node, "pointer", (void *)p_tnode); - insertInTail(tnode_list, s_node); - if_safeModeForNode = 1; - } - else - { - Node *s_node = initNode(); - initMallocValueForTNode(s_node, "pointer", (void *)p_tnode); - insertInTail(tnode_list, s_node); - } - } - return p_tnode; -} - -Tree *initTree(void) { - Tree *p_tree = (Tree *)malloc(sizeof(Tree)); - p_tree->id = getId(); - p_tree->root = NULL; - if (if_safeModeForTree) { - if (if_safeModeForNode) { - if_safeModeForNode = 0; - Node *s_node = initNode(); - initMallocValueForTNode(s_node, "pointer", (void *)p_tree); - if_safeModeForNode = 1; - insertInTail(tree_list, s_node); - } - else - { - Node *s_node = initNode(); - initMallocValueForTNode(s_node, "pointer", (void *)p_tree); - insertInTail(tree_list, s_node); - } - } - return p_tree; -} - -int *initMallocValueForTNode(TNode *p_tnode, char *type, void *value) { - p_tnode->type = type; - p_tnode->value = value; - p_tnode->if_malloc = 1; - return 0; -} - -int addChildInLeft(TNode *f_tnode, TNode *c_tnode) { - Node *p_node = initNode(); - initMalllocValueForNode(p_node, "pointer", c_tnode); - insertInHead(f_tnode->home, p_node); - c_tnode->father = f_tnode; - f_tnode->child_num++; - return 0; -} - -int addChildInRight(TNode *f_tnode, TNode *c_tnode) { - Node *p_node = initNode(); - initMalllocValueForNode(p_node, "pointer", c_tnode); - insertInTail(f_tnode->home, p_node); - c_tnode->father = f_tnode; - f_tnode->child_num++; - return 0; -} - -TNode *getBrotherInLeft(TNode *p_tnode) { - List *p_home = p_tnode->father->home; - Node *p_node =p_home->head; - int index = getIndexByNode(p_home, p_node); - if (index > 0) return findByIndexForNode(p_home, index -1); - return NULL; -} - -TNode *getBrotherInRight(TNode *p_tnode) { - List *p_home = p_tnode->father->home; - Node *p_node = p_home->head; - int index = getIndexByNode(p_home, p_node); - if (index < p_home->length-1) return findByIndexForNode(p_home, index + 1); - return NULL; -} - -int removeChildInLeft(TNode *p_tnode) { - TNode *c_tnode = p_tnode->home->head; - c_tnode->father = NULL; - releaseOnlyNode(c_tnode->room); - c_tnode->room = NULL; - p_tnode->child_num--; - popFromHead(p_tnode->home); -} - -int removeChildInRight(TNode *p_tnode) { - TNode *c_tnode = p_tnode->home->tail; - c_tnode->father = NULL; - releaseOnlyNode(c_tnode->room); - c_tnode->room = NULL; - p_tnode->child_num--; - popFromTail(p_tnode->home); -} - -unsigned long long target_id = 0; -TNode *target_value_id = NULL; -TNode*_dogetChildById(char *type, void *value); - -TNode *getChildById(TNode *p_tnode, unsigned long long id) { - List *p_home = p_tnode->home; - target_id = 0; - target_value_id = NULL; - listThrough(p_home, _dogetChildById); - if (target_value_id != NULL) { - return target_value_id; - } - return NULL; -} - -TNode*_dogetChildById(char *type, void *value) { - if (!strcmp(type, "pointer")) { - TNode *p_tode = (TNode *)value; - if (p_tode->id == target_id) { - target_value_id = p_tode; - return -1; - } - } - return 0; -} - -char *target_type = NULL; -void *target_value = NULL; -TNode *target_value_value = NULL; -TNode*_dogetChildByValue(char *type, void *value); - -TNode *getChildByValue(TNode *p_tnode, char *type, void *value) { - List *p_home = p_tnode->home; - target_value = value; - target_type = type; - target_value_value = NULL; - listThrough(p_home, _dogetChildByValue); - if (target_value_value != NULL) { - return target_value_value; - } - return NULL; -} - -TNode*_dogetChildByValue(char *type, void *value) { - if (!strcmp(type, target_type)) { - TNode *p_tode = (TNode *)value; - if (!strcmp(target_value, "int")) { - if (*(int *)p_tode->value == *(int *)target_value) - { - target_value_value = p_tode; - return -1; - } - } - else if (!strcmp(target_value, "double")) - { - if (*(double *)p_tode->value == *(double *)target_value) - { - target_value_value = p_tode; - return -1; - } - } - else if (!strcmp(target_value, "string")) - { - if (!strcmp((char *)p_tode->value,(char *)target_value)) - { - target_value_value = p_tode; - return -1; - } - } - else if (!strcmp(target_value, "pointer")) - { - if (p_tode->value == target_value) - { - target_value_value = p_tode; - return -1; - } - } - - } - return 0; -} - -int removeChildById(TNode *p_tnode, unsigned long long id) { - TNode *t_tnode = getChildById(p_tnode, id); - if (t_tnode != NULL) { - TNode *p_fnode = t_tnode->father; - p_fnode->child_num--; - removeById(p_fnode->home, t_tnode->room->id); - releaseOnlyNode(t_tnode->room); - t_tnode->room = NULL; - return 0; - } - return -1; -} - -int removeChildByValue(TNode *p_tnode, char *type, void *value) { - TNode *t_tnode = getChildByValue(p_tnode, type, value); - if (t_tnode != NULL) { - TNode *p_fnode = t_tnode->father; - p_fnode->child_num--; - removeById(p_fnode->home, t_tnode->room->id); - releaseOnlyNode(t_tnode->room); - t_tnode->room = NULL; - return 0; - } - return -1; -} - -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) - { - while (p_node != NULL) { - m_index++; - p_node = p_node->next; - } - return (TNode *)p_node->value; - } - return NULL; -} - -unsigned long long getIndexByChild(TNode *f_tnode, TNode *c_tnode) { - List *p_home = f_tnode->home; - Node *p_node = p_home->head; - int m_index = 0; - while (p_node != NULL) { - TNode *p_tnode = (TNode *)p_node->value; - if (p_tnode->id == c_tnode->id) { - return m_index; - } - m_index++; - p_node = p_node->next; - } - return NULL; -} - -int removeChildByIndex(TNode *p_tnode, unsigned long long index){ - TNode *t_tnode = getChildByIndex(p_tnode, index); - if (t_tnode != NULL) { - TNode *p_fnode = t_tnode->father; - p_fnode->child_num--; - removeById(p_fnode->home, t_tnode->room->id); - releaseOnlyNode(t_tnode->room); - t_tnode->room = NULL; - return 0; - } - return -1; -} - -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 (_doTreeThroughDown(getChildByIndex(p_tnode, i), 1, func) == -1) { - break; - } - } - } - } - return 0; -} - -int _doTreeThroughUp(TNode *p_tnode, int height, int(*func)(TNode *, unsigned long long height)) { - if (p_tnode->child_num > 0) { - for (int i = 0; i < p_tnode->child_num; i++) { - if (_doTreeThroughDown(getChildByIndex(p_tnode, i), height + 1, func)) return -1; - } - } - int func_back = func(p_tnode, height); - if (func_back == -1)return -1; - return 0; -} - -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); - for (int i = 0; i < p_tnode->child_num; i++) { - if (_doTreeThroughDown(getChildByIndex(p_tnode, i), 1, func) == -1) { - break; - } - } - } - } - return 0; -} - -int _doTreeThroughDown(TNode *p_tnode, int height, int(*func)(TNode *, unsigned long long height)) { - int func_back = func(p_tnode, height); - if (p_tnode->child_num > 0) { - for (int i = 0; i < p_tnode->child_num; i++) { - if (_doTreeThroughDown(getChildByIndex(p_tnode, i), height + 1, func)) return -1; - } - } - if (func_back == -1)return -1; - return 0; -} - -int TreeTravel(Tree *p_tree, int(*func)(TNode *, unsigned long long height)) { - TNode *p_tnode = p_tree->root; - unsigned long long height = 0; - if (p_tnode != NULL) { - int func_back = func(p_tnode, height); - while (func_back > -2) { - if (func_back > -1) { - p_tnode = getChildByIndex(func_back,func_back); - func(p_tnode, height + 1); - } - else - { - p_tnode = p_tnode->father; - func(p_tnode, height - 1); - - } - } - } - return 0; -} -int releaseTNode(TNode *p_tnode) { - if(p_tnode->child_num == 0){ - releaseList(p_tnode->home); - if (p_tnode->father != NULL) { - removeChildById(p_tnode->father, p_tnode->id); - } - if (strcmp(p_tnode->type, "pointer")) { - if (!strcmp(p_tnode->type, "list")) { - releaseList((List *)p_tnode->value); - } - else { - free(p_tnode->value); - } - } - p_tnode->value = NULL; - p_tnode->type = NULL; - p_tnode->id = 0; - p_tnode->if_malloc = 0; - free(p_tnode); - } - return 0; -} - -int _doreleaseTree(TNode *p_tnode, int height); - -int releaseTree(Tree *p_tree) { - TreeThroughUp(p_tree, _doreleaseTree); - p_tree->root = NULL; - p_tree->id = 0; - free(p_tree); -} - -int _doreleaseTree(TNode *p_tnode, int height) { - releaseTNode(p_tnode); - return 0; -} +unsigned long long target_id; +TNode *target_value_id; -int releaseOnlyTree(Tree *p_tree) { - p_tree->id = 0; - p_tree->root = NULL; - free(p_tree); - return 0; -} - -int releaseOnlyTNode(TNode *p_tnode) { - releaseList(p_tnode->home); - if (strcmp(p_tnode->type, "pointer")) { - if (!strcmp(p_tnode->type, "list")) { - releaseList((List *)p_tnode->value); - } - else { - free(p_tnode->value); - } - } - p_tnode->value = NULL; - p_tnode->type = NULL; - p_tnode->id = 0; - p_tnode->if_malloc = 0; - free(p_tnode); - return 0; -} - -int releaseAllForTree(void) { - if (if_safeModeForTree) { - if_safeModeForTree = 0; - Node *p_node = tnode_list->head; - while (p_node != NULL) { - TNode *p_tnode = (TNode *)p_node->value; - releaseOnlyTNode(p_tnode); - } - Node *p_node = tree_list->head; - while (p_node != NULL) { - Tree *p_tree = (Tree *)p_node->value; - releaseOnlyTree(p_tree); - } - releaseList(tnode_list); - releaseList(tree_list); - } - return 0; -} \ No newline at end of file +#endif \ No newline at end of file From 42fb87bacdbafc8b0144c0e5d668b16dd2aea10d Mon Sep 17 00:00:00 2001 From: Saturneric Date: Wed, 13 Jun 2018 16:04:51 +0800 Subject: [PATCH 19/31] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E4=B8=8E=E4=BF=AE?= =?UTF-8?q?=E6=94=B9=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- list/list.c | Bin 20414 -> 20250 bytes list/list_expand.c | 2 +- test.c | 10 +++ test.h | 1 + tree/tree.c | 31 +++++-- tree/tree.h | 9 ++- tree/tree_expand.c | 197 +++++++++++++++++++++++++++++++++++++++++++++ tree/tree_expand.h | 21 +++++ 8 files changed, 260 insertions(+), 11 deletions(-) create mode 100644 tree/tree_expand.c create mode 100644 tree/tree_expand.h diff --git a/list/list.c b/list/list.c index e434c5a7b85155ae381b82bd6411fdc32bc6d9ba..5807c185967f5e568911ee5e02c9692e55d3834a 100644 GIT binary patch delta 201 zcmdltpK;baMyCJ&CI>N@O-^9d5;kD4X5eMuV(?+eWGH4RVNhVun(WUkIXQ=$OI?9M z9|%_jL_~jx;7dE+-%{4pw6j1DL%l4s_~a~Z9&t?d|E6Sg=xr`%dd)joM?qln138Y# z4*p`3SMcg=?h{~=n4DnAFS6`CBT?KF9vsoLZlx?+<9 YB-ti!(U1f3c{b0`j$_u(hMN=74 zfcz4Md@z{`6e$6-GQjFUWFk;SDnk)a6sBJTXbQ-L5(Yh>*_uESY8_BbI8Y>&ArERs zJ;<^GpyqsrETC{Q*l>hn^1#M`G^8--K(!!bAxy+0Co&WrUa}D*=j5v ztp{3J1XP#^Rt_?v5@iyFjxVx36Px+_J diff --git a/list/list_expand.c b/list/list_expand.c index a5f8fb3..3a756bc 100644 --- a/list/list_expand.c +++ b/list/list_expand.c @@ -120,7 +120,7 @@ void printList(List *p_list) { printf("%s", (char *)(p_node->value)); } else if (!strcmp(p_node->type, "pointer")) { - printf("%s", (char *)(p_node->value)); + printf("%p", (char *)(p_node->value)); } else if (!strcmp(p_node->type, "list")) { printList((List *)p_node->value); diff --git a/test.c b/test.c index c21a0f5..14423f9 100644 --- a/test.c +++ b/test.c @@ -1,5 +1,6 @@ #include "test.h" + int list(void) { init_rand(); safeModeForNode(1); @@ -39,6 +40,15 @@ int list(void) { int tree(void) { safeModeForTree(1); Tree *t_tree = initTree(); + TNode *t_tnode = tnodeWithInt(1), *cr_tnode = tnodeWithInt(3),*cl_tnode = tnodeWithInt(2); + addChildInRight(t_tnode, cl_tnode); + addChildInRight(t_tnode, cr_tnode); + addChildInRight(cl_tnode, tnodeWithInt(4)); + addChildInRight(cl_tnode, tnodeWithInt(5)); + addChildInRight(cr_tnode, tnodeWithInt(6)); + addChildInRight(cr_tnode, tnodeWithInt(7)); + printTNodeWithFamily(t_tnode, 0); + //removeChildByIndex(t_tnode, 0); releaseAllForTree(); return 0; } diff --git a/test.h b/test.h index cba9876..3e171ce 100644 --- a/test.h +++ b/test.h @@ -6,6 +6,7 @@ #include "list/list_expand.h" #include "stack/stack_expand.h" #include "tree/tree.h" +#include "tree/tree_expand.h" int stack(void); int list(void); diff --git a/tree/tree.c b/tree/tree.c index 8d981e8..0d42a14 100644 --- a/tree/tree.c +++ b/tree/tree.c @@ -1,5 +1,9 @@ #include"tree.h" +unsigned long long target_id = 0; +TNode *target_value_id = NULL; +int if_safeModeForTree = 0; + int safeModeForTree(int ifon) { if (ifon == 1) { if (tnode_list == NULL && tree_list == NULL) { @@ -86,6 +90,7 @@ int addChildInLeft(TNode *f_tnode, TNode *c_tnode) { initMallocValueForNode(p_node, "pointer", c_tnode); insertInHead(f_tnode->home, p_node); c_tnode->father = f_tnode; + c_tnode->room = p_node; f_tnode->child_num++; return 0; } @@ -95,6 +100,7 @@ int addChildInRight(TNode *f_tnode, TNode *c_tnode) { initMallocValueForNode(p_node, "pointer", c_tnode); insertInTail(f_tnode->home, p_node); c_tnode->father = f_tnode; + c_tnode->room = p_node; f_tnode->child_num++; return 0; } @@ -246,7 +252,7 @@ TNode *getChildByIndex(TNode *p_tnode, unsigned long long index) { int m_index = 0; if (index < p_tnode->child_num - 1) { - while (p_node != NULL) { + while (p_node != NULL && m_index < index) { m_index++; p_node = p_node->next; } @@ -273,7 +279,7 @@ unsigned long long getIndexByChild(TNode *f_tnode, TNode *c_tnode) { int removeChildByIndex(TNode *p_tnode, unsigned long long index) { TNode *t_tnode = getChildByIndex(p_tnode, index); if (t_tnode != NULL) { - TNode *p_fnode = t_tnode->father; + TNode *p_fnode = t_tnode->father; p_fnode->child_num--; removeById(p_fnode->home, t_tnode->room->id); releaseOnlyNode(t_tnode->room); @@ -402,12 +408,14 @@ int releaseOnlyTree(Tree *p_tree) { int releaseOnlyTNode(TNode *p_tnode) { releaseList(p_tnode->home); - if (strcmp(p_tnode->type, "pointer")) { - if (!strcmp(p_tnode->type, "list")) { - releaseList((List *)p_tnode->value); - } - else { - free(p_tnode->value); + if (p_tnode->if_malloc) { + if (strcmp(p_tnode->type, "pointer")) { + if (!strcmp(p_tnode->type, "list")) { + releaseList((List *)p_tnode->value); + } + else { + free(p_tnode->value); + } } } p_tnode->value = NULL; @@ -425,14 +433,21 @@ int releaseAllForTree(void) { while (p_node != NULL) { TNode *p_tnode = (TNode *)p_node->value; releaseOnlyTNode(p_tnode); + p_node = p_node->next; } p_node = tree_list->head; while (p_node != NULL) { Tree *p_tree = (Tree *)p_node->value; releaseOnlyTree(p_tree); + p_node = p_node->next; } releaseList(tnode_list); releaseList(tree_list); } return 0; } + +int setRoot(Tree *p_tree, TNode *p_tnode) { + p_tree->root = p_tnode; + return 0; +} diff --git a/tree/tree.h b/tree/tree.h index 3f5a7ae..ac06ac7 100644 --- a/tree/tree.h +++ b/tree/tree.h @@ -20,8 +20,7 @@ typedef struct tree TNode *root; }Tree; -List *tree_list; -List *tnode_list; + int if_safeModeForTree; int safeModeForTree(int ifon); int releaseAllForTree(void); @@ -58,6 +57,8 @@ int releaseOnlyTree(Tree *p_tree); int releaseTNode(TNode *p_tnode); int releaseOnlyTNode(TNode *p_tnode); +int setRoot(Tree *p_tree, TNode *p_tnode); + char *target_type; void *target_value; TNode *target_value_value; @@ -65,5 +66,9 @@ TNode *target_value_value; unsigned long long target_id; TNode *target_value_id; +List *tree_list; +List *tnode_list; +int if_safeModeForTree; + #endif \ No newline at end of file diff --git a/tree/tree_expand.c b/tree/tree_expand.c new file mode 100644 index 0000000..478929a --- /dev/null +++ b/tree/tree_expand.c @@ -0,0 +1,197 @@ +#include "tree_expand.h" + +TNode *tnodeWithInt(int temp) { + TNode *p_tnode = initTNode(); + int *p_temp = (int *)malloc(sizeof(int)); + *p_temp = temp; + initMallocValueForTNode(p_tnode, "int", p_temp); + return p_tnode; +} + +TNode *tnodeWithDouble(double temp) { + TNode *p_tnode = initTNode(); + double *p_temp = (double *)malloc(sizeof(double)); + *p_temp = temp; + initMallocValueForTNode(p_tnode, "double", p_temp); + return p_tnode; +} +TNode *tnodeWithString(char *temp) { + TNode *p_tnode = initTNode(); + char *p_temp = (char *)malloc(sizeof(temp)); + strcpy_s(p_temp, sizeof(p_temp), temp); + initMallocValueForTNode(p_tnode, "double", p_temp); + return p_tnode; +} + +TNode *tnodeWithPointer(void *temp) { + TNode *p_tnode = initTNode(); + initMallocValueForTNode(p_tnode, "pointer", temp); + return p_tnode; +} + +int getValueByIntForTree(TNode *p_tnode) { + if (!strcmp(p_tnode->type, "int")) { + return *(int *)p_tnode->value; + } + return -1; +} + +double getValueByDoubleForTree(TNode *p_tnode) { + if (!strcmp(p_tnode->type, "double")) { + return *(double *)p_tnode->value; + } + return -1; +} + +char *getValueByStringForTree(TNode *p_tnode) { + if (!strcmp(p_tnode->type, "string")) { + return (char *)p_tnode->value; + } + return NULL; +} + +void *getValueByPointerForTree(TNode *p_tnode) { + if (!strcmp(p_tnode->type, "pointer")) { + return p_tnode->value; + } + return NULL; +} + +int printTNode(TNode *p_tnode, int priority) { + 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: "); + if (p_tnode->if_malloc) { + printf("YES\n"); + for (int i = 0; i < priority + 1; i++) printf(" "); + printf("Value(type: %s): ", p_tnode->type); + if (!strcmp(p_tnode->type, "int")) { + printf("%d\n", *(int *)(p_tnode->value)); + } + else if (!strcmp(p_tnode->type, "double")) { + printf("%a\n", *(double *)(p_tnode->value)); + } + else if (!strcmp(p_tnode->type, "string")) { + printf("%s\n", (char *)(p_tnode->value)); + } + else if (!strcmp(p_tnode->type, "pointer")) { + printf("%p\n", (char *)(p_tnode->value)); + } + } + else printf("NO\n"); + + if (p_tnode->child_num > 0) { + for (int i = 0; i < priority + 1; i++) printf(" "); + printf("Child number: %llu\n", p_tnode->child_num); + } + return 0; +} + +int printTNodeWithHome(TNode *p_tnode,int priority) { + 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: "); + if (p_tnode->if_malloc) { + printf("YES\n"); + for (int i = 0; i < priority + 1; i++) printf(" "); + printf("Value(type: %s): ", p_tnode->type); + if (!strcmp(p_tnode->type, "int")) { + printf("%d\n", *(int *)(p_tnode->value)); + } + else if (!strcmp(p_tnode->type, "double")) { + printf("%a\n", *(double *)(p_tnode->value)); + } + else if (!strcmp(p_tnode->type, "string")) { + printf("%s\n", (char *)(p_tnode->value)); + } + else if (!strcmp(p_tnode->type, "pointer")) { + printf("%p\n", (char *)(p_tnode->value)); + } + } + else printf("NO\n"); + + if (p_tnode->father != NULL) { + for (int i = 0; i < priority + 1; i++) printf(" "); + printf("Father id: %llu\n", p_tnode->father->id); + } + else + { + for (int i = 0; i < priority + 1; i++) printf(" "); + printf("Father: NO\n"); + } + + if (p_tnode->child_num > 0) { + for (int i = 0; i < priority + 1; i++) printf(" "); + printf("Child(number: %llu):\n", p_tnode->child_num); + } + + List *p_home = p_tnode->home; + Node *p_node = p_home->head; + while (p_node != NULL) { + printTNode((TNode *)p_node->value,priority+2); + p_node = p_node->next; + } + return 0; +} + +int printTNodeWithFamily(TNode *p_tnode, int priority) { + 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: "); + if (p_tnode->if_malloc) { + printf("YES\n"); + for (int i = 0; i < priority + 1; i++) printf(" "); + printf("Value(type: %s): ", p_tnode->type); + if (!strcmp(p_tnode->type, "int")) { + printf("%d\n", *(int *)(p_tnode->value)); + } + else if (!strcmp(p_tnode->type, "double")) { + printf("%a\n", *(double *)(p_tnode->value)); + } + else if (!strcmp(p_tnode->type, "string")) { + printf("%s\n", (char *)(p_tnode->value)); + } + else if (!strcmp(p_tnode->type, "pointer")) { + printf("%p\n", (char *)(p_tnode->value)); + } + } + else printf("NO\n"); + + if (p_tnode->father != NULL) { + for (int i = 0; i < priority + 1; i++) printf(" "); + printf("Father id: %llu\n", p_tnode->father->id); + } + else + { + for (int i = 0; i < priority + 1; i++) printf(" "); + printf("Father: NO\n"); + } + + if (p_tnode->child_num > 0) { + for (int i = 0; i < priority + 1; i++) printf(" "); + printf("Child(number: %llu):\n", p_tnode->child_num); + } + + List *p_home = p_tnode->home; + Node *p_node = p_home->head; + while (p_node != NULL) { + printTNodeWithFamily((TNode *)p_node->value, priority + 2); + p_node = p_node->next; + } + return 0; +} + +int printTree(Tree *p_tree) { + printf("###"); + printf("Tree(id: %llu)",p_tree->id); + printTNodeWithFamily(p_tree->root,0); + return 0; +} \ No newline at end of file diff --git a/tree/tree_expand.h b/tree/tree_expand.h new file mode 100644 index 0000000..d8d882a --- /dev/null +++ b/tree/tree_expand.h @@ -0,0 +1,21 @@ +#ifndef TREE_EXPAND_H +#define TREE_EXPAND_H + +#include "tree.h" + +TNode *tnodeWithInt(int); +TNode *tnodeWithDouble(double); +TNode *tnodeWithString(char *); +TNode *tnodeWithPointer(void *); + +int getValueByIntForTree(TNode *); +double getValueByDoubleForTree(TNode *); +char *getValueByStringForTree(TNode *); +void *getValueByPointerForTree(TNode *); + +int printTree(Tree *p_tree); +int printTNodeWithHome(TNode *p_tnode, int priority); +int printTNodeWithFamily(TNode *p_tnode, int priority); +int printTNode(TNode *p_tnode, int priority); + +#endif From 896e454c4076c0d9cbe9c7fe20ff2258536f4f2f Mon Sep 17 00:00:00 2001 From: Saturneric Date: Wed, 13 Jun 2018 16:15:25 +0800 Subject: [PATCH 20/31] debug --- list/list.c | Bin 20250 -> 20432 bytes list/list_expand.c | 48 ++++++++++++++++++++++++++------------------- test.c | 3 ++- tree/tree.c | 2 +- 4 files changed, 31 insertions(+), 22 deletions(-) diff --git a/list/list.c b/list/list.c index 5807c185967f5e568911ee5e02c9692e55d3834a..005cfa229c63b3a436d4f8b9f8cfb1de9a9d8e3b 100644 GIT binary patch delta 55 zcmbO=kMY8M#tnKJllNF~O!iQho17rcF*#3NX7WERi^)84DwDVA$xW8fmIJbRHtT4s LF>dbB>{A5*BVH0K delta 23 fcmcaGpK;ba#tnKJn^$SaF;3=D6WAQ2Ri_F7Zy^Xi 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++; From 880fa14d10539cc0214c3cee782198c37bea1810 Mon Sep 17 00:00:00 2001 From: Saturneric Date: Wed, 13 Jun 2018 16:32:39 +0800 Subject: [PATCH 21/31] =?UTF-8?q?=E6=B5=8B=E8=AF=95=E4=B8=8Edebug=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test.c | 16 +++- tree/tree.c | 6 +- tree/tree_expand.c | 226 +++++++++++++++++++++++---------------------- 3 files changed, 133 insertions(+), 115 deletions(-) diff --git a/test.c b/test.c index 89b0134..4eaf628 100644 --- a/test.c +++ b/test.c @@ -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; } diff --git a/tree/tree.c b/tree/tree.c index 9c0c123..1bd035e 100644 --- a/tree/tree.c +++ b/tree/tree.c @@ -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) { + func(p_tnode, 0); if (p_tree->root->child_num > 0) { - func(p_tnode, 0); for (int i = 0; i < p_tnode->child_num; i++) { if (_doTreeThroughDown(getChildByIndex(p_tnode, i), 1, func) == -1) { break; diff --git a/tree/tree_expand.c b/tree/tree_expand.c index 478929a..062934d 100644 --- a/tree/tree_expand.c +++ b/tree/tree_expand.c @@ -58,135 +58,145 @@ void *getValueByPointerForTree(TNode *p_tnode) { } int printTNode(TNode *p_tnode, int priority) { - 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: "); - if (p_tnode->if_malloc) { - printf("YES\n"); + 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("Value(type: %s): ", p_tnode->type); - if (!strcmp(p_tnode->type, "int")) { - printf("%d\n", *(int *)(p_tnode->value)); + printf("ifMalloc: "); + if (p_tnode->if_malloc) { + printf("YES\n"); + for (int i = 0; i < priority + 1; i++) printf(" "); + printf("Value(type: %s): ", p_tnode->type); + if (!strcmp(p_tnode->type, "int")) { + printf("%d\n", *(int *)(p_tnode->value)); + } + else if (!strcmp(p_tnode->type, "double")) { + printf("%a\n", *(double *)(p_tnode->value)); + } + else if (!strcmp(p_tnode->type, "string")) { + printf("%s\n", (char *)(p_tnode->value)); + } + else if (!strcmp(p_tnode->type, "pointer")) { + printf("%p\n", (char *)(p_tnode->value)); + } } - else if (!strcmp(p_tnode->type, "double")) { - printf("%a\n", *(double *)(p_tnode->value)); - } - else if (!strcmp(p_tnode->type, "string")) { - printf("%s\n", (char *)(p_tnode->value)); - } - else if (!strcmp(p_tnode->type, "pointer")) { - printf("%p\n", (char *)(p_tnode->value)); + else printf("NO\n"); + + if (p_tnode->child_num > 0) { + for (int i = 0; i < priority + 1; i++) printf(" "); + printf("Child number: %llu\n", p_tnode->child_num); } + return 0; } - else printf("NO\n"); - - if (p_tnode->child_num > 0) { - for (int i = 0; i < priority + 1; i++) printf(" "); - printf("Child number: %llu\n", p_tnode->child_num); - } - return 0; + return -1; } int printTNodeWithHome(TNode *p_tnode,int priority) { - 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: "); - if (p_tnode->if_malloc) { - printf("YES\n"); + if (p_tnode != NULL) { + if (priority == 0) printf("###"); + else printf("#"); + printf("TNode(id: %llu)\n", p_tnode->id); for (int i = 0; i < priority + 1; i++) printf(" "); - printf("Value(type: %s): ", p_tnode->type); - if (!strcmp(p_tnode->type, "int")) { - printf("%d\n", *(int *)(p_tnode->value)); + printf("ifMalloc: "); + if (p_tnode->if_malloc) { + printf("YES\n"); + for (int i = 0; i < priority + 1; i++) printf(" "); + printf("Value(type: %s): ", p_tnode->type); + if (!strcmp(p_tnode->type, "int")) { + printf("%d\n", *(int *)(p_tnode->value)); + } + else if (!strcmp(p_tnode->type, "double")) { + printf("%a\n", *(double *)(p_tnode->value)); + } + else if (!strcmp(p_tnode->type, "string")) { + printf("%s\n", (char *)(p_tnode->value)); + } + else if (!strcmp(p_tnode->type, "pointer")) { + printf("%p\n", (char *)(p_tnode->value)); + } } - else if (!strcmp(p_tnode->type, "double")) { - printf("%a\n", *(double *)(p_tnode->value)); - } - else if (!strcmp(p_tnode->type, "string")) { - printf("%s\n", (char *)(p_tnode->value)); - } - else if (!strcmp(p_tnode->type, "pointer")) { - printf("%p\n", (char *)(p_tnode->value)); - } - } - else printf("NO\n"); + else printf("NO\n"); - if (p_tnode->father != NULL) { - for (int i = 0; i < priority + 1; i++) printf(" "); - printf("Father id: %llu\n", p_tnode->father->id); - } - else - { - for (int i = 0; i < priority + 1; i++) printf(" "); - printf("Father: NO\n"); - } - - if (p_tnode->child_num > 0) { - for (int i = 0; i < priority + 1; i++) printf(" "); - printf("Child(number: %llu):\n", p_tnode->child_num); - } + if (p_tnode->father != NULL) { + for (int i = 0; i < priority + 1; i++) printf(" "); + printf("Father id: %llu\n", p_tnode->father->id); + } + else + { + for (int i = 0; i < priority + 1; i++) printf(" "); + printf("Father: NO\n"); + } - List *p_home = p_tnode->home; - Node *p_node = p_home->head; - while (p_node != NULL) { - printTNode((TNode *)p_node->value,priority+2); - p_node = p_node->next; + if (p_tnode->child_num > 0) { + for (int i = 0; i < priority + 1; i++) printf(" "); + printf("Child(number: %llu):\n", p_tnode->child_num); + } + + List *p_home = p_tnode->home; + Node *p_node = p_home->head; + while (p_node != NULL) { + printTNode((TNode *)p_node->value, priority + 2); + p_node = p_node->next; + } + return 0; } - return 0; + return -1; } int printTNodeWithFamily(TNode *p_tnode, int priority) { - 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: "); - if (p_tnode->if_malloc) { - printf("YES\n"); + 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("Value(type: %s): ", p_tnode->type); - if (!strcmp(p_tnode->type, "int")) { - printf("%d\n", *(int *)(p_tnode->value)); + printf("ifMalloc: "); + if (p_tnode->if_malloc) { + printf("YES\n"); + for (int i = 0; i < priority + 1; i++) printf(" "); + printf("Value(type: %s): ", p_tnode->type); + if (!strcmp(p_tnode->type, "int")) { + printf("%d\n", *(int *)(p_tnode->value)); + } + else if (!strcmp(p_tnode->type, "double")) { + printf("%a\n", *(double *)(p_tnode->value)); + } + else if (!strcmp(p_tnode->type, "string")) { + printf("%s\n", (char *)(p_tnode->value)); + } + else if (!strcmp(p_tnode->type, "pointer")) { + printf("%p\n", (char *)(p_tnode->value)); + } } - else if (!strcmp(p_tnode->type, "double")) { - printf("%a\n", *(double *)(p_tnode->value)); - } - else if (!strcmp(p_tnode->type, "string")) { - printf("%s\n", (char *)(p_tnode->value)); - } - else if (!strcmp(p_tnode->type, "pointer")) { - printf("%p\n", (char *)(p_tnode->value)); - } - } - else printf("NO\n"); + else printf("NO\n"); - if (p_tnode->father != NULL) { - for (int i = 0; i < priority + 1; i++) printf(" "); - printf("Father id: %llu\n", p_tnode->father->id); - } - else - { - for (int i = 0; i < priority + 1; i++) printf(" "); - printf("Father: NO\n"); - } + if (p_tnode->father != NULL) { + for (int i = 0; i < priority + 1; i++) printf(" "); + printf("Father id: %llu\n", p_tnode->father->id); + } + else + { + for (int i = 0; i < priority + 1; i++) printf(" "); + printf("Father: NO\n"); + } - if (p_tnode->child_num > 0) { - for (int i = 0; i < priority + 1; i++) printf(" "); - printf("Child(number: %llu):\n", p_tnode->child_num); - } + if (p_tnode->child_num > 0) { + for (int i = 0; i < priority + 1; i++) printf(" "); + printf("Child(number: %llu):\n", p_tnode->child_num); + } - List *p_home = p_tnode->home; - Node *p_node = p_home->head; - while (p_node != NULL) { - printTNodeWithFamily((TNode *)p_node->value, priority + 2); - p_node = p_node->next; + List *p_home = p_tnode->home; + Node *p_node = p_home->head; + while (p_node != NULL) { + printTNodeWithFamily((TNode *)p_node->value, priority + 2); + p_node = p_node->next; + } + return 0; } - return 0; + return -1; } int printTree(Tree *p_tree) { From 79b529a84147bf5633bb489d62c52bda75d644a4 Mon Sep 17 00:00:00 2001 From: Saturneric Date: Wed, 18 Jul 2018 11:53:09 +0800 Subject: [PATCH 22/31] Change code to meet the need of the tools which not support C99. --- list/list.c | Bin 20432 -> 20522 bytes list/list.h | Bin 3888 -> 3892 bytes list/list_expand.c | 75 +++++++++++++++++++++++++++------------------ test.c | 24 ++++++++++----- tree/tree.c | 39 ++++++++++++++--------- tree/tree_expand.c | 45 +++++++++++++++------------ 6 files changed, 111 insertions(+), 72 deletions(-) diff --git a/list/list.c b/list/list.c index 005cfa229c63b3a436d4f8b9f8cfb1de9a9d8e3b..1d99126d208d1cb974a160368e83e7badac35619 100644 GIT binary patch delta 127 zcmcaGpK;X!#tmwGlPfs*CQslOn;appwb_BsiE(ou|2)RYI>vmH1z5Qz&y(VqtfU~Z z*+npqadMTC(B=z55zO3~40#MC3jr<(X{6C$ae)e;ecG62UfzNP-~Ghead; - for (unsigned long long i = 0; i < m_index; i++) { + unsigned long long i; + for (i = 0; i < m_index; i++) { p_node = p_node->next; } return p_node; @@ -86,28 +90,29 @@ void *getByPointerForNode(Node *p_node) { } void printListInfo(List *p_list, int priority) { - for (int i = 0; i < priority; i++) printf(" "); - printf("###LIST(location:%p, id:%llu){\n", p_list, p_list->id); - for (int i = 0; i < priority + 1; i++) printf(" "); - printf("HEAD->%p / Tail->%p / Length:%llu\n", p_list->head, p_list->tail, p_list->length); - Node *p_node = p_list->head; int i = 0; + Node *p_node; + for (i = 0; i < priority; i++) printf(" "); + printf("###LIST(location:%p, id:%llu){\n", p_list, p_list->id); + for (i = 0; i < priority + 1; i++) printf(" "); + printf("HEAD->%p / Tail->%p / Length:%llu\n", p_list->head, p_list->tail, p_list->length); + p_node = p_list->head; while (p_node != NULL) { - for (int i = 0; i < priority + 1; i++) printf(" "); + for (i = 0; i < priority + 1; i++) printf(" "); printf("%d.... \n", i); printNodeInfo(p_node, priority + 1); p_node = p_node->next; i++; } - for (int i = 0; i < priority; i++) printf(" "); + for (i = 0; i < priority; i++) printf(" "); printf("}\n"); } void printList(List *p_list) { + int if_nearLast = 0; Node *p_node = p_list->head; printf("["); - int if_nearLast = 0; while (p_node != NULL) { if (!if_nearLast && p_node->next == NULL) if_nearLast = 1; if (!strcmp(p_node->type, "int")) { @@ -134,44 +139,46 @@ void printList(List *p_list) { } void printNodeInfo(Node *p_node, int priority) { - for (int i = 0; i < priority; i++) printf(" "); + int i; + for (i = 0; i < priority; i++) printf(" "); printf("#NODE(location:%p, id:%llu){\n", p_node, p_node->id); - for (int i = 0; i < priority + 1; i++) printf(" "); + for (i = 0; i < priority + 1; i++) printf(" "); 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(" "); + for (i = 0; i < priority + 1; i++) printf(" "); 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(" "); + for (i = 0; i < priority + 1; i++) printf(" "); 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(" "); + for (i = 0; i < priority + 1; i++) printf(" "); 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(" "); + for (i = 0; i < priority + 1; i++) printf(" "); 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(" "); + for (i = 0; i < priority + 1; i++) printf(" "); printf("VALUE(List):\n"); printListInfo((List *)p_node->value, priority + 2); } - for (int i = 0; i < priority; i++) printf(" "); + for (i = 0; i < priority; i++) printf(" "); printf("}\n"); } void printNode(Node *p_node) { + int i; printf("#NODE(location:%p, id:%llu){\n", p_node, p_node->id); printf(" "); printf("NEXT->%p / LAST->%p\n", p_node->next, p_node->last, p_node->if_malloc); - for (int i = 0; i < 1; i++) printf(" "); + for (i = 0; i < 1; i++) printf(" "); printf("ifMalloc: "); if (p_node->if_malloc) { printf("YES\n"); - for (int i = 0; i < 1; i++) printf(" "); + for (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)); @@ -196,25 +203,28 @@ void printNode(Node *p_node) { Node *findByIntForNode(List *p_list, int target) { + Node *t_node; int *p_target = (int *)malloc(sizeof(int)); *p_target = target; - Node *t_node = findByValue(p_list, "int", p_target); + t_node = findByValue(p_list, "int", p_target); free(p_target); return t_node; } Node *findByDoubleForNode(List *p_list, double target) { + Node *t_node; double *p_target = (double *)malloc(sizeof(double)); *p_target = target; - Node *t_node = findByValue(p_list, "double", p_target); + t_node = findByValue(p_list, "double", p_target); free(p_target); return t_node; } Node *findByStringForNode(List *p_list, char *target) { + Node *t_node; char *p_temp = (char *)malloc(sizeof(char)*(strlen(target) + 1)); strcpy_s(p_temp, sizeof(p_temp), target); - Node *t_node = findByValue(p_list, "string", p_temp); + t_node = findByValue(p_list, "string", p_temp); free(p_temp); return t_node; } @@ -225,9 +235,11 @@ Node *findByPointerForNode(List *p_list, void *target) { } int addValueForComplex(Node * p_node, char *type, void *value) { + List *c_list; + Node *c_node; if (!strcmp(p_node->type, "list")) { - List *c_list = (List *)p_node->value; - Node *c_node = initNode(); + c_list = (List *)p_node->value; + c_node = initNode(); initMallocValueForNode(c_node, type, value); insertInTail(c_list, c_node); return 0; @@ -275,24 +287,27 @@ int addPointerForComplex(Node *p_node, void *temp) { List *m_findByInt(List* p_list, int temp) { int *p_temp = (int *)malloc(sizeof(int)); + List *t_list; *p_temp = temp; - List *t_list = mply_findByValue(p_list, "int", (void *)p_temp); + t_list = mply_findByValue(p_list, "int", (void *)p_temp); free(p_temp); return t_list; } List *m_findByDouble(List* p_list, double temp) { + List *t_list; double *p_temp = (double *)malloc(sizeof(double)); *p_temp = temp; - List *t_list = mply_findByValue(p_list, "double", (void *)p_temp); + t_list = mply_findByValue(p_list, "double", (void *)p_temp); free(p_temp); return t_list; } List *m_findByString(List* p_list, char *temp) { + List *t_list; char *p_temp = (char *)malloc(sizeof(char)*(strlen(temp) + 1)); strcpy_s(p_temp, sizeof(p_temp), temp); - List *t_list = mply_findByValue(p_list, "string", (void *)p_temp); + t_list = mply_findByValue(p_list, "string", (void *)p_temp); free(p_temp); return t_list; } diff --git a/test.c b/test.c index 4eaf628..5347f93 100644 --- a/test.c +++ b/test.c @@ -2,9 +2,11 @@ int list(void) { + int i; + List *t_list, *m_list;; init_rand(); safeModeForNode(1); - List *t_list = initList(); + t_list = initList(); /*for(int i = 0; i < 9; i++){ Node *t_node = initNode(); @@ -18,7 +20,7 @@ int list(void) { insertInTail(t_list,t_node); initMalllocValue(t_node,(void *)"there");*/ - for (int i = 0; i < 12; i++) { + for (i = 0; i < 12; i++) { insertInHead(t_list, nodeWithInt(i)); insertInTail(t_list, nodeWithInt(i)); } @@ -27,7 +29,7 @@ int list(void) { printListInfo(t_list, 0); printList(t_list); - List *m_list; + m_list = m_findByIntForNode(t_list, 5); printList(m_list); printf("\n"); @@ -44,13 +46,18 @@ int _useTreeThroughDown(TNode *p_tnode, unsigned long long height) { int tree(void) { + TNode *t_tnode, *cr_tnode, *cl_tnode; + Tree *t_tree; + TNode *gs_tnode; safeModeForTree(1); - Tree *t_tree = initTree(); - TNode *t_tnode = tnodeWithInt(1), *cr_tnode = tnodeWithInt(3),*cl_tnode = tnodeWithInt(2); + t_tree = initTree(); + t_tnode = tnodeWithInt(1); + cr_tnode = tnodeWithInt(3); + cl_tnode = tnodeWithInt(2); addChildInRight(t_tnode, cl_tnode); addChildInRight(t_tnode, cr_tnode); addChildInRight(cl_tnode, tnodeWithInt(4)); - TNode *gs_tnode = tnodeWithInt(5); + gs_tnode = tnodeWithInt(5); addChildInRight(cl_tnode,gs_tnode); addChildInRight(cr_tnode, tnodeWithInt(6)); addChildInRight(cr_tnode, tnodeWithInt(7)); @@ -63,11 +70,12 @@ int tree(void) { } int stack(void) { + int i; Stack *t_stack = initStack(); - for (int i = 0; i < 10; i++) { + for (i = 0; i < 10; i++) { pushStack(t_stack, snodeWithInt(i)); } - for (int i = 0; i < 10; i++) { + for (i = 0; i < 10; i++) { printf("%d", getValueByIntForSNode(popStack(t_stack))); } releaseStack(t_stack); diff --git a/tree/tree.c b/tree/tree.c index 1bd035e..6b15c5a 100644 --- a/tree/tree.c +++ b/tree/tree.c @@ -29,6 +29,7 @@ int safeModeForTree(int ifon) { } TNode *initTNode(void) { + Node *s_node; TNode *p_tnode = (TNode *)malloc(sizeof(TNode)); p_tnode->id = getId(); p_tnode->child_num = 0; @@ -41,14 +42,14 @@ TNode *initTNode(void) { if (if_safeModeForTree) { if (if_safeModeForNode) { if_safeModeForNode = 0; - Node *s_node = initNode(); + s_node = initNode(); initMallocValueForNode(s_node, "pointer", (void *)p_tnode); insertInTail(tnode_list, s_node); if_safeModeForNode = 1; } else { - Node *s_node = initNode(); + s_node = initNode(); initMallocValueForNode(s_node, "pointer", (void *)p_tnode); insertInTail(tnode_list, s_node); } @@ -57,20 +58,21 @@ TNode *initTNode(void) { } Tree *initTree(void) { + Node *s_node; Tree *p_tree = (Tree *)malloc(sizeof(Tree)); p_tree->id = getId(); p_tree->root = NULL; if (if_safeModeForTree) { if (if_safeModeForNode) { if_safeModeForNode = 0; - Node *s_node = initNode(); + s_node = initNode(); initMallocValueForNode(s_node, "pointer", (void *)p_tree); if_safeModeForNode = 1; insertInTail(tree_list, s_node); } else { - Node *s_node = initNode(); + s_node = initNode(); initMallocValueForNode(s_node, "pointer", (void *)p_tree); insertInTail(tree_list, s_node); } @@ -184,14 +186,14 @@ TNode *getChildByValue(TNode *p_tnode, char *type, void *value) { int _dogetChildByValue(const char *type, void *value) { if (!strcmp(type, target_type)) { TNode *p_tode = (TNode *)value; - if (!strcmp(target_value, "int")) { + if (!strcmp((char *)target_value, "int")) { if (*(int *)p_tode->value == *(int *)target_value) { target_value_value = p_tode; return -1; } } - else if (!strcmp(target_value, "double")) + else if (!strcmp((char *)target_value, "double")) { if (*(double *)p_tode->value == *(double *)target_value) { @@ -199,7 +201,7 @@ int _dogetChildByValue(const char *type, void *value) { return -1; } } - else if (!strcmp(target_value, "string")) + else if (!strcmp((char *)target_value, "string")) { if (!strcmp((char *)p_tode->value, (char *)target_value)) { @@ -207,7 +209,7 @@ int _dogetChildByValue(const char *type, void *value) { return -1; } } - else if (!strcmp(target_value, "pointer")) + else if (!strcmp((char *)target_value, "pointer")) { if (p_tode->value == target_value) { @@ -291,10 +293,11 @@ int removeChildByIndex(TNode *p_tnode, unsigned long long index) { int TreeThroughUp(Tree *p_tree, int(*func)(TNode *, unsigned long long height)) { + int i; TNode *p_tnode = p_tree->root; if (p_tnode != NULL) { if (p_tnode->child_num > 0) { - for (int i = 0; i < p_tnode->child_num; i++) { + for (i = 0; i < p_tnode->child_num; i++) { if (_doTreeThroughUp(getChildByIndex(p_tnode, i), 1, func) == -1) { break; } @@ -306,23 +309,26 @@ int TreeThroughUp(Tree *p_tree, int(*func)(TNode *, unsigned long long height)) } int _doTreeThroughUp(TNode *p_tnode, int height, int(*func)(TNode *, unsigned long long height)) { + int i, func_back; + if (p_tnode->child_num > 0) { - for (int i = 0; i < p_tnode->child_num; i++) { + for (i = 0; i < p_tnode->child_num; i++) { if (_doTreeThroughUp(getChildByIndex(p_tnode, i), height + 1, func)) return -1; } } - int func_back = func(p_tnode, height); + func_back = func(p_tnode, height); if (func_back == -1)return -1; return 0; } int TreeThroughDown(Tree *p_tree, int(*func)(TNode *, unsigned long long height)) { + int i; TNode *p_tnode = p_tree->root; if (p_tree->root != NULL) { func(p_tnode, 0); if (p_tree->root->child_num > 0) { - for (int i = 0; i < p_tnode->child_num; i++) { + for (i = 0; i < p_tnode->child_num; i++) { if (_doTreeThroughDown(getChildByIndex(p_tnode, i), 1, func) == -1) { break; } @@ -333,9 +339,10 @@ int TreeThroughDown(Tree *p_tree, int(*func)(TNode *, unsigned long long height) } int _doTreeThroughDown(TNode *p_tnode, int height, int(*func)(TNode *, unsigned long long height)) { + int i; int func_back = func(p_tnode, height); if (p_tnode->child_num > 0) { - for (int i = 0; i < p_tnode->child_num; i++) { + for (i = 0; i < p_tnode->child_num; i++) { if (_doTreeThroughDown(getChildByIndex(p_tnode, i), height + 1, func)) return -1; } } @@ -427,9 +434,11 @@ int releaseOnlyTNode(TNode *p_tnode) { } int releaseAllForTree(void) { + Node *p_node; + Tree *p_tree; if (if_safeModeForTree) { if_safeModeForTree = 0; - Node *p_node = tnode_list->head; + p_node = tnode_list->head; while (p_node != NULL) { TNode *p_tnode = (TNode *)p_node->value; releaseOnlyTNode(p_tnode); @@ -437,7 +446,7 @@ int releaseAllForTree(void) { } p_node = tree_list->head; while (p_node != NULL) { - Tree *p_tree = (Tree *)p_node->value; + p_tree = (Tree *)p_node->value; releaseOnlyTree(p_tree); p_node = p_node->next; } diff --git a/tree/tree_expand.c b/tree/tree_expand.c index 062934d..353526a 100644 --- a/tree/tree_expand.c +++ b/tree/tree_expand.c @@ -58,17 +58,18 @@ void *getValueByPointerForTree(TNode *p_tnode) { } int printTNode(TNode *p_tnode, int priority) { + int i; if (p_tnode != NULL) { - for (int i = 0; i < priority; i++) printf(" "); + for (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(" "); + for (i = 0; i < priority + 1; i++) printf(" "); printf("ifMalloc: "); if (p_tnode->if_malloc) { printf("YES\n"); - for (int i = 0; i < priority + 1; i++) printf(" "); + for (i = 0; i < priority + 1; i++) printf(" "); printf("Value(type: %s): ", p_tnode->type); if (!strcmp(p_tnode->type, "int")) { printf("%d\n", *(int *)(p_tnode->value)); @@ -86,7 +87,7 @@ int printTNode(TNode *p_tnode, int priority) { else printf("NO\n"); if (p_tnode->child_num > 0) { - for (int i = 0; i < priority + 1; i++) printf(" "); + for (i = 0; i < priority + 1; i++) printf(" "); printf("Child number: %llu\n", p_tnode->child_num); } return 0; @@ -95,15 +96,18 @@ int printTNode(TNode *p_tnode, int priority) { } int printTNodeWithHome(TNode *p_tnode,int priority) { + int i; + List *p_home; + Node *p_node; if (p_tnode != NULL) { if (priority == 0) printf("###"); else printf("#"); printf("TNode(id: %llu)\n", p_tnode->id); - for (int i = 0; i < priority + 1; i++) printf(" "); + for (i = 0; i < priority + 1; i++) printf(" "); printf("ifMalloc: "); if (p_tnode->if_malloc) { printf("YES\n"); - for (int i = 0; i < priority + 1; i++) printf(" "); + for (i = 0; i < priority + 1; i++) printf(" "); printf("Value(type: %s): ", p_tnode->type); if (!strcmp(p_tnode->type, "int")) { printf("%d\n", *(int *)(p_tnode->value)); @@ -121,22 +125,22 @@ int printTNodeWithHome(TNode *p_tnode,int priority) { else printf("NO\n"); if (p_tnode->father != NULL) { - for (int i = 0; i < priority + 1; i++) printf(" "); + for (i = 0; i < priority + 1; i++) printf(" "); printf("Father id: %llu\n", p_tnode->father->id); } else { - for (int i = 0; i < priority + 1; i++) printf(" "); + for (i = 0; i < priority + 1; i++) printf(" "); printf("Father: NO\n"); } if (p_tnode->child_num > 0) { - for (int i = 0; i < priority + 1; i++) printf(" "); + for (i = 0; i < priority + 1; i++) printf(" "); printf("Child(number: %llu):\n", p_tnode->child_num); } - List *p_home = p_tnode->home; - Node *p_node = p_home->head; + p_home = p_tnode->home; + p_node = p_home->head; while (p_node != NULL) { printTNode((TNode *)p_node->value, priority + 2); p_node = p_node->next; @@ -147,16 +151,19 @@ int printTNodeWithHome(TNode *p_tnode,int priority) { } int printTNodeWithFamily(TNode *p_tnode, int priority) { + int i; + List *p_home; + Node *p_node; if (p_tnode != NULL) { - for (int i = 0; i < priority; i++) printf(" "); + for (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(" "); + for (i = 0; i < priority + 1; i++) printf(" "); printf("ifMalloc: "); if (p_tnode->if_malloc) { printf("YES\n"); - for (int i = 0; i < priority + 1; i++) printf(" "); + for (i = 0; i < priority + 1; i++) printf(" "); printf("Value(type: %s): ", p_tnode->type); if (!strcmp(p_tnode->type, "int")) { printf("%d\n", *(int *)(p_tnode->value)); @@ -174,22 +181,22 @@ int printTNodeWithFamily(TNode *p_tnode, int priority) { else printf("NO\n"); if (p_tnode->father != NULL) { - for (int i = 0; i < priority + 1; i++) printf(" "); + for (i = 0; i < priority + 1; i++) printf(" "); printf("Father id: %llu\n", p_tnode->father->id); } else { - for (int i = 0; i < priority + 1; i++) printf(" "); + for (i = 0; i < priority + 1; i++) printf(" "); printf("Father: NO\n"); } if (p_tnode->child_num > 0) { - for (int i = 0; i < priority + 1; i++) printf(" "); + for (i = 0; i < priority + 1; i++) printf(" "); printf("Child(number: %llu):\n", p_tnode->child_num); } - List *p_home = p_tnode->home; - Node *p_node = p_home->head; + p_home = p_tnode->home; + p_node = p_home->head; while (p_node != NULL) { printTNodeWithFamily((TNode *)p_node->value, priority + 2); p_node = p_node->next; From a3f202d1c4dd864e50a92af012d3b430354361ed Mon Sep 17 00:00:00 2001 From: Saturneric Date: Wed, 18 Jul 2018 11:59:55 +0800 Subject: [PATCH 23/31] Fix. --- list/list.c | Bin 20522 -> 20542 bytes 1 file changed, 0 insertions(+), 0 deletions(-) diff --git a/list/list.c b/list/list.c index 1d99126d208d1cb974a160368e83e7badac35619..89448fed414f7ed84d016ce8dc180dc901b2ac83 100644 GIT binary patch delta 33 pcmZ3rfN|df#tlI}lR3O3Cg%u>Y>xBsVq`3tyx!S*^9NrmCIHoi3?l#l delta 39 vcmdnDfN|9V#tlI}n~QwH7$=)4@=Z?g;hL=A#WwkXv)1H0!cv>%{1lh~DX Date: Wed, 18 Jul 2018 12:44:13 +0800 Subject: [PATCH 24/31] Fixed. --- graph/graph.c | 1 + graph/graph.h | 24 ++++++++++++++++++++++++ list/list.c | Bin 20542 -> 20546 bytes list/list.h | Bin 3892 -> 3934 bytes tree/tree.h | 29 ++++++++++++++--------------- 5 files changed, 39 insertions(+), 15 deletions(-) create mode 100644 graph/graph.c create mode 100644 graph/graph.h diff --git a/graph/graph.c b/graph/graph.c new file mode 100644 index 0000000..e43cd57 --- /dev/null +++ b/graph/graph.c @@ -0,0 +1 @@ +#include "graph.h" \ No newline at end of file diff --git a/graph/graph.h b/graph/graph.h new file mode 100644 index 0000000..6a092c6 --- /dev/null +++ b/graph/graph.h @@ -0,0 +1,24 @@ +#ifndef GRAPH_H +#define GRAPH_H + +#include "../list/list_expand.h" + +typedef struct GNode{ + unsigned long long id; + void *value; + List *routes; + int if_setValue; +}GNode; + +typedef struct route{ + unsigned long long id; + double distance; + int if_setValue; + GNode from, to; +}Route; + +GNode *initGNode(void); +Route *initRoute(void); + + +#endif \ No newline at end of file diff --git a/list/list.c b/list/list.c index 89448fed414f7ed84d016ce8dc180dc901b2ac83..96a722a730d176cd9a70b8874d2419ba5730f28f 100644 GIT binary patch delta 13 VcmdnDfbq}*#tn7>lOIU3001j+1(5&% delta 9 QcmX@KfN|df#tn7>02WpR0RR91 diff --git a/list/list.h b/list/list.h index bc8f2f670b9b4de6453bd63f72ab0553bfe6a732..6c0e250de764b32d1c2c9f5f3c26bee99c66b12a 100644 GIT binary patch delta 61 pcmdlYcTa9Z86R&kLkUA75N9$ZGbl_h Date: Sat, 21 Jul 2018 18:39:09 +0800 Subject: [PATCH 25/31] Add. --- tree/tree.c | 9 +++++++++ tree/tree.h | 14 ++++++++++++++ 2 files changed, 23 insertions(+) create mode 100644 tree/tree.c create mode 100644 tree/tree.h diff --git a/tree/tree.c b/tree/tree.c new file mode 100644 index 0000000..28b903e --- /dev/null +++ b/tree/tree.c @@ -0,0 +1,9 @@ +// +// tree.c +// ZE-Standard-Libraries +// +// Created by 胡一兵 on 2018/6/11. +// Copyright © 2018年 ZE. All rights reserved. +// + +#include "tree.h" diff --git a/tree/tree.h b/tree/tree.h new file mode 100644 index 0000000..f1f866b --- /dev/null +++ b/tree/tree.h @@ -0,0 +1,14 @@ +// +// tree.h +// ZE-Standard-Libraries +// +// Created by 胡一兵 on 2018/6/11. +// Copyright © 2018年 ZE. All rights reserved. +// + +#ifndef tree_h +#define tree_h + +#include + +#endif /* tree_h */ From 6aa9b8d7084dd51f3f308c31c3db78242063432c Mon Sep 17 00:00:00 2001 From: Saturneic Date: Mon, 23 Jul 2018 12:59:16 +0800 Subject: [PATCH 26/31] Fix type type. --- graph/graph.h | 2 +- list/list.c | Bin 20546 -> 11900 bytes list/list.h | Bin 3934 -> 2325 bytes list/list_expand.c | 110 +++++++++++++++++++++---------------------- list/list_expand.h | Bin 3374 -> 2366 bytes stack/stack.c | Bin 2886 -> 1531 bytes stack/stack.h | Bin 1276 -> 624 bytes stack/stack_expand.c | 20 ++++---- stack/stack_expand.h | Bin 838 -> 401 bytes test.c | 5 +- test.h | 3 +- tree/tree.c | 61 ++++++++++++------------ tree/tree.h | 39 ++++++--------- tree/tree_expand.c | 50 ++++++++++---------- type/type.h | 21 +++++++++ 15 files changed, 159 insertions(+), 152 deletions(-) create mode 100644 type/type.h diff --git a/graph/graph.h b/graph/graph.h index 6a092c6..c1db03d 100644 --- a/graph/graph.h +++ b/graph/graph.h @@ -21,4 +21,4 @@ GNode *initGNode(void); Route *initRoute(void); -#endif \ No newline at end of file +#endif diff --git a/list/list.c b/list/list.c index 96a722a730d176cd9a70b8874d2419ba5730f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cH~2&Giyo1-JH~e%c*-r^(t|h78q1I1S5-43^u(`nNmlv_q9)3IWSa#FKToQ+GGRmwM6?xU z#>8&VbuiO})*9`2emx*E_Z?sxg&%#qUB_YaI%4ro zWkC0;#;3}QJGt`IXEVED@UYm5lxB>!I#jp`Wpr$&x9^EXYmJv$sqX>K zyTiND`))!NDJK2Qp);_On6v&aG1ucqJB|09&kytWuRguJc*5EWgIwXc$HC@AW3sOO zgS_UkBIE89+0~39vl!!y>c@U&^eCgkxA0z*(=m>><6Okp!C91qplp7vIz?tidCE&s#vge?atstx3@79%OG7WtNk+P#a8M?;wb-q$fiithi^n31U z2a)i!*g}LnV|{o}<3HCo(@BU-eVW!d&^BeJ4eI6-x+-=AuvNDuaEU)e~i9Xr%E zkODm40Gi3K?w+Kqj8`qJN#&5{D`q~-pIRvwA8gsR2hm%R9+y#L*AUU@3LCzDbPefx zDmEiZ14mdrl;MB#^bHIB)6&K+qd}p zo_kRFGni&~;NBz> zzj{~Dn^YLwE!{cMbDH-Ob8=O&|Fp8qf1%-bQ*)>4U#~35-0ybl_%3(}9+;zV3u_yC ggJxY{htype = "list"; + p_node->type = LIST; p_node->value = initList(); p_node->if_malloc = 1; return p_node; @@ -50,7 +50,7 @@ Node *findByIndexForNode(List *p_list, unsigned long long m_index) { return p_node; } -int listThrough(List *p_list, int(*p_func)(const char *, void *)) { +int listThrough(List *p_list, int(*p_func)(int, void *)) { Node *p_node = p_list->head; while (p_node != NULL) { if (p_node->if_malloc == 1) { @@ -70,22 +70,22 @@ int listThrough(List *p_list, int(*p_func)(const char *, void *)) { } int getByIntForNode(Node *p_node) { - if (!strcmp(p_node->type, "int")) return *(int *)(p_node->value); + if (p_node->type == INT) return *(int *)(p_node->value); else return -1; } char *getByStringForNode(Node *p_node) { - if (!strcmp(p_node->type, "string")) return (char *)(p_node->value); + if (p_node->type == STRING) return (char *)(p_node->value); else return NULL; } double getByDoubleForNode(Node *p_node) { - if (!strcmp(p_node->type, "double")) return *(double *)(p_node->value); + if (p_node->type == DOUBLE) return *(double *)(p_node->value); else return -1; } void *getByPointerForNode(Node *p_node) { - if (!strcmp(p_node->type, "pointer")) return (void *)(p_node->value); + if (p_node->type == POINTER) return (void *)(p_node->value); else return NULL; } @@ -115,19 +115,19 @@ void printList(List *p_list) { printf("["); while (p_node != NULL) { if (!if_nearLast && p_node->next == NULL) if_nearLast = 1; - if (!strcmp(p_node->type, "int")) { + if (p_node->type == INT) { printf("%d", *(int *)(p_node->value)); } - else if (!strcmp(p_node->type, "double")) { + else if (p_node->type == DOUBLE) { printf("%a", *(double *)(p_node->value)); } - else if (!strcmp(p_node->type, "string")) { + else if (p_node->type == STRING) { printf("%s", (char *)(p_node->value)); } - else if (!strcmp(p_node->type, "pointer")) { + else if (p_node->type == POINTER) { printf("%p", (char *)(p_node->value)); } - else if (!strcmp(p_node->type, "list")) { + else if (p_node->type == LIST) { printList((List *)p_node->value); } if (!if_nearLast) { @@ -144,23 +144,23 @@ void printNodeInfo(Node *p_node, int priority) { printf("#NODE(location:%p, id:%llu){\n", p_node, p_node->id); for (i = 0; i < priority + 1; i++) printf(" "); printf("NEXT->%p / LAST->%p / MALLOC:%d\n", p_node->next, p_node->last, p_node->if_malloc); - if (!strcmp(p_node->type, "int")) { + if (p_node->type == INT) { for (i = 0; i < priority + 1; i++) printf(" "); printf("VALUE(int):%d\n", *(int *)(p_node->value)); } - else if (!strcmp(p_node->type, "double")) { + else if (p_node->type == DOUBLE) { for (i = 0; i < priority + 1; i++) printf(" "); printf("VALUE(double):%a\n", *(double *)(p_node->value)); } - else if (!strcmp(p_node->type, "string")) { + else if (p_node->type == STRING) { for (i = 0; i < priority + 1; i++) printf(" "); printf("VALUE(string):%s\n", (char *)(p_node->value)); } - else if (!strcmp(p_node->type, "pointer")) { + else if (p_node->type == POINTER) { for (i = 0; i < priority + 1; i++) printf(" "); printf("VALUE(pointer):%s\n", (char *)(p_node->value)); } - else if (!strcmp(p_node->type, "list")) { + else if (p_node->type == LIST) { for (i = 0; i < priority + 1; i++) printf(" "); printf("VALUE(List):\n"); printListInfo((List *)p_node->value, priority + 2); @@ -173,26 +173,26 @@ void printNode(Node *p_node) { int i; printf("#NODE(location:%p, id:%llu){\n", p_node, p_node->id); printf(" "); - printf("NEXT->%p / LAST->%p\n", p_node->next, p_node->last, p_node->if_malloc); + printf("NEXT->%p / LAST->%p\n", p_node->next, p_node->last); for (i = 0; i < 1; i++) printf(" "); printf("ifMalloc: "); if (p_node->if_malloc) { printf("YES\n"); for (i = 0; i < 1; i++) printf(" "); - printf("Value(type: %s): ", p_node->type); - if (!strcmp(p_node->type, "int")) { + printf("Value(type: %d): ", p_node->type); + if (p_node->type == INT) { printf("%d", *(int *)(p_node->value)); } - else if (!strcmp(p_node->type, "double")) { + else if (p_node->type == DOUBLE) { printf("%a\n", *(double *)(p_node->value)); } - else if (!strcmp(p_node->type, "string")) { + else if (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 (p_node->type == POINTER) { + printf("%p\n", (char *)(p_node->value)); } - else if (!strcmp(p_node->type, "list")) { + else if (p_node->type == LIST) { printList((List *)p_node->value); } } @@ -206,7 +206,7 @@ Node *findByIntForNode(List *p_list, int target) { Node *t_node; int *p_target = (int *)malloc(sizeof(int)); *p_target = target; - t_node = findByValue(p_list, "int", p_target); + t_node = findByValue(p_list, INT, p_target); free(p_target); return t_node; } @@ -215,7 +215,7 @@ Node *findByDoubleForNode(List *p_list, double target) { Node *t_node; double *p_target = (double *)malloc(sizeof(double)); *p_target = target; - t_node = findByValue(p_list, "double", p_target); + t_node = findByValue(p_list, DOUBLE, p_target); free(p_target); return t_node; } @@ -223,21 +223,21 @@ Node *findByDoubleForNode(List *p_list, double target) { Node *findByStringForNode(List *p_list, char *target) { Node *t_node; char *p_temp = (char *)malloc(sizeof(char)*(strlen(target) + 1)); - strcpy_s(p_temp, sizeof(p_temp), target); - t_node = findByValue(p_list, "string", p_temp); + strcpy(p_temp, target); + t_node = findByValue(p_list, STRING, p_temp); free(p_temp); return t_node; } Node *findByPointerForNode(List *p_list, void *target) { - Node *t_node = findByValue(p_list, "pointer", target); + Node *t_node = findByValue(p_list, POINTER, target); return t_node; } -int addValueForComplex(Node * p_node, char *type, void *value) { +int addValueForComplex(Node * p_node, int type, void *value) { List *c_list; Node *c_node; - if (!strcmp(p_node->type, "list")) { + if (p_node->type == LIST) { c_list = (List *)p_node->value; c_node = initNode(); initMallocValueForNode(c_node, type, value); @@ -248,38 +248,38 @@ int addValueForComplex(Node * p_node, char *type, void *value) { } int addIntForComplex(Node *p_node, int temp) { - if (!strcmp(p_node->type, "list")) { + if (p_node->type == LIST) { int *p_temp = (int *)malloc(sizeof(int)); *p_temp = temp; - addValueForComplex(p_node, "int", p_temp); + addValueForComplex(p_node, INT, p_temp); return 0; } return -1; } int addDoubleForComplex(Node *p_node, double temp) { - if (!strcmp(p_node->type, "list")) { + if (p_node->type == LIST) { double *p_temp = (double *)malloc(sizeof(double)); *p_temp = temp; - addValueForComplex(p_node, "double", p_temp); + addValueForComplex(p_node, DOUBLE, p_temp); return 0; } return -1; } int addStringForComplex(Node *p_node, char *temp) { - if (!strcmp(p_node->type, "list")) { + if (p_node->type == LIST) { char *p_temp = (char *)malloc(sizeof(strlen(temp) + 1)); - strcpy_s(p_temp, sizeof(p_temp), temp); - addValueForComplex(p_node, "string", p_temp); + strcpy(p_temp, temp); + addValueForComplex(p_node, STRING, p_temp); return 0; } return -1; } int addPointerForComplex(Node *p_node, void *temp) { - if (!strcmp(p_node->type, "list")) { - addValueForComplex(p_node, "pointer", temp); + if (p_node->type == LIST) { + addValueForComplex(p_node, POINTER, temp); return 0; } return -1; @@ -289,7 +289,7 @@ List *m_findByInt(List* p_list, int temp) { int *p_temp = (int *)malloc(sizeof(int)); List *t_list; *p_temp = temp; - t_list = mply_findByValue(p_list, "int", (void *)p_temp); + t_list = mply_findByValue(p_list, INT, (void *)p_temp); free(p_temp); return t_list; } @@ -298,7 +298,7 @@ List *m_findByDouble(List* p_list, double temp) { List *t_list; double *p_temp = (double *)malloc(sizeof(double)); *p_temp = temp; - t_list = mply_findByValue(p_list, "double", (void *)p_temp); + t_list = mply_findByValue(p_list, DOUBLE, (void *)p_temp); free(p_temp); return t_list; } @@ -306,14 +306,14 @@ List *m_findByDouble(List* p_list, double temp) { List *m_findByString(List* p_list, char *temp) { List *t_list; char *p_temp = (char *)malloc(sizeof(char)*(strlen(temp) + 1)); - strcpy_s(p_temp, sizeof(p_temp), temp); - t_list = mply_findByValue(p_list, "string", (void *)p_temp); + strcpy(p_temp, temp); + t_list = mply_findByValue(p_list, STRING, (void *)p_temp); free(p_temp); return t_list; } List *m_findByPointer(List* p_list, void *temp) { - List *t_list = mply_findByValue(p_list, "double", (void *)temp); + List *t_list = mply_findByValue(p_list, DOUBLE, (void *)temp); return t_list; } @@ -331,21 +331,21 @@ unsigned long long getIndexByNode(List *p_list, Node *p_node) { List *m_findByIntForNode(List* p_list, int temp) { int *p_temp = (int *)malloc(sizeof(int)); *p_temp = temp; - return mply_findByValue(p_list, "int", (void *)p_temp); + return mply_findByValue(p_list, INT, (void *)p_temp); } List *m_findByDoubleForNode(List* p_list, double temp) { double *p_temp = (double *)malloc(sizeof(double)); *p_temp = temp; - return mply_findByValue(p_list, "double", (void *)p_temp); + return mply_findByValue(p_list, DOUBLE, (void *)p_temp); } List *m_findByStringForNode(List* p_list, char *temp) { char *p_temp = (char *)malloc(sizeof(char) * (strlen(temp) + 1)); - strcpy_s(p_temp, sizeof(p_temp), temp); - return mply_findByValue(p_list, "string", (void *)p_temp); + strcpy(p_temp, temp); + return mply_findByValue(p_list, STRING, (void *)p_temp); } List *m_findByPointerForNode(List* p_list, void *temp) { - return mply_findByValue(p_list, "pointer", (void *)temp); + return mply_findByValue(p_list, POINTER, (void *)temp); } diff --git a/list/list_expand.h b/list/list_expand.h index e2f32e93f8cb09789ef0ab4230bd9d77b18a929c..a9d210f4e06f12ac35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1m?rLw33BAoVuJt^*9Wa*Xu!A2nh};Xgvu@VRCSoDGi3qNAlONZfck`4$ kW*sJE{81a-dA(MW85czA=eJoVDKse@ppyCfN062H1_^r2^Z)<= literal 1276 zcmbVMT}#725S(Yh{}AX)Euud_5kwF{^d;hJiRnjzu?_hsO7X9&Gj}~N*HEoeN-uk} zvopKfe0~g&V}TR}T1+rSgmctrcrJMJgcD@Az#$IISLhk>Le7Yd@qkNQ;TB`uY!LQN ztYYgU#MR&pCGQ=NDppjG@;5T|6P};Ry1>$))`mUetv)T|HMPu5l?fvSaSJ|oPdPKs zf;_2G1-TgG1qt(%nQq}y!zNV`?=s>lo<@AOxV}iG3{dU)7w|iz--}!y7YEBWq-rBNyg_9type, "int")) return *(int *)p_snode->value; + if (p_snode->type == INT) return *(int *)p_snode->value; else return -1; } double getValueByDoubleForSNode(SNode *p_snode) { - if (!strcmp(p_snode->type, "double")) return *(double *)p_snode->value; + if (p_snode->type == DOUBLE) return *(double *)p_snode->value; else return -1; } char *getValueByStringForSNode(SNode *p_snode) { - if (!strcmp(p_snode->type, "int")) return (char *)p_snode->value; + if (p_snode->type == STRING) return (char *)p_snode->value; else return NULL; } void *getValueByPointerForSNode(SNode *p_snode) { - if (!strcmp(p_snode->type, "int")) return (void *)p_snode->value; + if (p_snode->type == POINTER) return (void *)p_snode->value; else return NULL; -} \ No newline at end of file +} diff --git a/stack/stack_expand.h b/stack/stack_expand.h index 300b68efb06b1eb147a2e3b461a5e23cdbe412f2..ba739f79634f43b2fb56b830143985bf0aec42da 100644 GIT binary patch literal 401 zcmZvYK?=e!6h!wqMKGJ#MLmEbs8tl96e{Yj)aKU&%a63F=VDnR(0%VX8&} zHO&u;)xKDtvqhQ|Tf(fS5PoIC6jn_yfX+J8D!j&WK4_!Pl+`VkBSP|2TPW(#o|7_i zhlVROF0G7w!c7-1YEEmMx6}ex_|MwEUr!Z~(DydIfVVn;w=g+q}`O+rvMr tY>Kb@!u*T?>5GRvzb63t0R#9M79a@&6so3^h`Jvu;CU}m6p}_0@&;<>h1dW9 literal 838 zcma))!AiqW5Jk^g@E=0m#4hXyD1ur=5u^}NccGfJ6{Sji75#bj&P#+T4fO3Y;m(~q z=gsfW9?vX!;*}K@H5o^I5NP86IR`8_W|ti{m4m39s{1AC22uB~oypf6XYwq#<%Bb? zDLLnXiK-jMsxCY4R%ux*!#2ImDCF?gWgaTYva9ZuJSg>*{si*4M_`}BIB8qgSS~9b z#iLel<*HPN!qLmcX2Dc6Glt0-CYov_f-*Ep@fquC&BF+^nvA)0fjiBySFAbZyW9Rk zosA=vyKkS!@7eF?xum-K-TN|nQmLMvMW5$7yHwZqW@|C8MAa^Kr1#3)eV5|;#k&}r Mrqrt%zfruYKZPxbvH$=8 diff --git a/test.c b/test.c index 5347f93..210d23f 100644 --- a/test.c +++ b/test.c @@ -2,7 +2,6 @@ int list(void) { - int i; List *t_list, *m_list;; init_rand(); safeModeForNode(1); @@ -20,7 +19,7 @@ int list(void) { insertInTail(t_list,t_node); initMalllocValue(t_node,(void *)"there");*/ - for (i = 0; i < 12; i++) { + for (int i = 0; i < 12; i++) { insertInHead(t_list, nodeWithInt(i)); insertInTail(t_list, nodeWithInt(i)); } @@ -87,4 +86,4 @@ int main(int argc, char **argv) { tree(); getchar(); return 0; -} \ No newline at end of file +} diff --git a/test.h b/test.h index 3e171ce..eed9bbc 100644 --- a/test.h +++ b/test.h @@ -12,5 +12,4 @@ int stack(void); int list(void); int tree(void); -#endif // TEST_H - +#endif // TEST_H diff --git a/tree/tree.c b/tree/tree.c index bab8420..5171631 100644 --- a/tree/tree.c +++ b/tree/tree.c @@ -1,8 +1,8 @@ #include"tree.h" -unsigned long long target_id = 0; -TNode *target_value_id = NULL; -int if_safeModeForTree = 0; +static unsigned long long target_id = 0; +static TNode *target_value_id = NULL; +static int if_safeModeForTree = 0; int safeModeForTree(int ifon) { if (ifon == 1) { @@ -36,21 +36,21 @@ TNode *initTNode(void) { p_tnode->father = NULL; p_tnode->if_malloc = 0; p_tnode->value = NULL; - p_tnode->type = NULL; + p_tnode->type = VOID; p_tnode->home = initList(); p_tnode->room = NULL; if (if_safeModeForTree) { if (if_safeModeForNode) { if_safeModeForNode = 0; s_node = initNode(); - initMallocValueForNode(s_node, "pointer", (void *)p_tnode); + initMallocValueForNode(s_node, POINTER, (void *)p_tnode); insertInTail(tnode_list, s_node); if_safeModeForNode = 1; } else { s_node = initNode(); - initMallocValueForNode(s_node, "pointer", (void *)p_tnode); + initMallocValueForNode(s_node, POINTER, (void *)p_tnode); insertInTail(tnode_list, s_node); } } @@ -66,21 +66,21 @@ Tree *initTree(void) { if (if_safeModeForNode) { if_safeModeForNode = 0; s_node = initNode(); - initMallocValueForNode(s_node, "pointer", (void *)p_tree); + initMallocValueForNode(s_node, POINTER, (void *)p_tree); if_safeModeForNode = 1; insertInTail(tree_list, s_node); } else { s_node = initNode(); - initMallocValueForNode(s_node, "pointer", (void *)p_tree); + initMallocValueForNode(s_node, POINTER, (void *)p_tree); insertInTail(tree_list, s_node); } } return p_tree; } -int *initMallocValueForTNode(TNode *p_tnode, char *type, void *value) { +int *initMallocValueForTNode(TNode *p_tnode, int type, void *value) { p_tnode->type = type; p_tnode->value = value; p_tnode->if_malloc = 1; @@ -89,7 +89,7 @@ int *initMallocValueForTNode(TNode *p_tnode, char *type, void *value) { int addChildInLeft(TNode *f_tnode, TNode *c_tnode) { Node *p_node = initNode(); - initMallocValueForNode(p_node, "pointer", c_tnode); + initMallocValueForNode(p_node, POINTER, c_tnode); insertInHead(f_tnode->home, p_node); c_tnode->father = f_tnode; c_tnode->room = p_node; @@ -99,7 +99,7 @@ int addChildInLeft(TNode *f_tnode, TNode *c_tnode) { int addChildInRight(TNode *f_tnode, TNode *c_tnode) { Node *p_node = initNode(); - initMallocValueForNode(p_node, "pointer", c_tnode); + initMallocValueForNode(p_node, POINTER, c_tnode); insertInTail(f_tnode->home, p_node); c_tnode->father = f_tnode; c_tnode->room = p_node; @@ -155,8 +155,8 @@ TNode *getChildById(TNode *p_tnode, unsigned long long id) { return NULL; } -int _dogetChildById(const char *type, void *value) { - if (!strcmp(type, "pointer")) { +int _dogetChildById(int type, void *value) { + if (type == POINTER) { TNode *p_tode = (TNode *)value; if (p_tode->id == target_id) { target_value_id = p_tode; @@ -166,12 +166,11 @@ int _dogetChildById(const char *type, void *value) { return 0; } -char *target_type = NULL; -void *target_value = NULL; -TNode *target_value_value = NULL; -int _dogetChildByValue(const char *type, void *value); +static int target_type = VOID; +static void *target_value = NULL; +static TNode *target_value_value = NULL; -TNode *getChildByValue(TNode *p_tnode, char *type, void *value) { +TNode *getChildByValue(TNode *p_tnode, int type, void *value) { List *p_home = p_tnode->home; target_value = value; target_type = type; @@ -183,17 +182,17 @@ TNode *getChildByValue(TNode *p_tnode, char *type, void *value) { return NULL; } -int _dogetChildByValue(const char *type, void *value) { - if (!strcmp(type, target_type)) { +int _dogetChildByValue(int type, void *value) { + if (type == target_type) { TNode *p_tode = (TNode *)value; - if (!strcmp((char *)target_value, "int")) { + if (target_type == INT) { if (*(int *)p_tode->value == *(int *)target_value) { target_value_value = p_tode; return -1; } } - else if (!strcmp((char *)target_value, "double")) + else if (target_type == DOUBLE) { if (*(double *)p_tode->value == *(double *)target_value) { @@ -201,7 +200,7 @@ int _dogetChildByValue(const char *type, void *value) { return -1; } } - else if (!strcmp((char *)target_value, "string")) + else if (target_type == STRING) { if (!strcmp((char *)p_tode->value, (char *)target_value)) { @@ -209,7 +208,7 @@ int _dogetChildByValue(const char *type, void *value) { return -1; } } - else if (!strcmp((char *)target_value, "pointer")) + else if (target_type == POINTER) { if (p_tode->value == target_value) { @@ -235,7 +234,7 @@ int removeChildById(TNode *p_tnode, unsigned long long id) { return -1; } -int removeChildByValue(TNode *p_tnode, char *type, void *value) { +int removeChildByValue(TNode *p_tnode, int type, void *value) { TNode *t_tnode = getChildByValue(p_tnode, type, value); if (t_tnode != NULL) { TNode *p_fnode = t_tnode->father; @@ -376,8 +375,8 @@ int releaseTNode(TNode *p_tnode) { if (p_tnode->father != NULL) { removeChildById(p_tnode->father, p_tnode->id); } - if (strcmp(p_tnode->type, "pointer")) { - if (!strcmp(p_tnode->type, "list")) { + if (p_tnode->type != POINTER) { + if (p_tnode->type == LIST) { releaseList((List *)p_tnode->value); } else { @@ -385,7 +384,7 @@ int releaseTNode(TNode *p_tnode) { } } p_tnode->value = NULL; - p_tnode->type = NULL; + p_tnode->type = VOID; p_tnode->id = 0; p_tnode->if_malloc = 0; free(p_tnode); @@ -416,8 +415,8 @@ int releaseOnlyTree(Tree *p_tree) { int releaseOnlyTNode(TNode *p_tnode) { releaseList(p_tnode->home); if (p_tnode->if_malloc) { - if (strcmp(p_tnode->type, "pointer")) { - if (!strcmp(p_tnode->type, "list")) { + if (p_tnode->type != STRING) { + if (p_tnode->type == LIST) { releaseList((List *)p_tnode->value); } else { @@ -426,7 +425,7 @@ int releaseOnlyTNode(TNode *p_tnode) { } } p_tnode->value = NULL; - p_tnode->type = NULL; + p_tnode->type = VOID; p_tnode->id = 0; p_tnode->if_malloc = 0; free(p_tnode); diff --git a/tree/tree.h b/tree/tree.h index c978da4..c2d950f 100644 --- a/tree/tree.h +++ b/tree/tree.h @@ -1,18 +1,8 @@ -<<<<<<< HEAD -// -// tree.h -// ZE-Standard-Libraries -// -// Created by 胡一兵 on 2018/6/11. -// Copyright © 2018年 ZE. All rights reserved. -// +#ifndef TREE_H +#define TREE_H -#ifndef tree_h -#define tree_h #include #include "../list/list_expand.h" -#ifndef TREE_H -#define TREE_H typedef struct tree_node { @@ -21,7 +11,7 @@ typedef struct tree_node struct tree_node *father; Node *room; unsigned long long child_num; - char *type; + int type; void *value; int if_malloc; }TNode; @@ -38,7 +28,7 @@ int releaseAllForTree(void); TNode *initTNode(void); Tree *initTree(void); -int *initMallocValueForTNode(TNode *p_tnode, char *type, void *value); +int *initMallocValueForTNode(TNode *p_tnode, int type, void *value); int addChildInLeft(TNode *f_tnode, TNode *c_tnode); int addChildInRight(TNode *f_tnode, TNode *c_tnode); @@ -47,30 +37,30 @@ TNode *getBrotherInRight(TNode *p_node); int removeChildInLeft(TNode *p_tnode); int removeChildInRight(TNode *p_tnode); TNode *getChildById(TNode *p_tnode, unsigned long long id); -TNode *getChildByValue(TNode *p_tnode, char *type, void *value); +TNode *getChildByValue(TNode *p_tnode, int type, void *value); TNode *getChildByIndex(TNode *p_tnode, unsigned long long index); unsigned long long getIndexByChild(TNode *f_tnode, TNode *c_tnode); int removeChildById(TNode *p_tnode, unsigned long long id); int removeChildByIndex(TNode *p_tnode, unsigned long long index); -int removeChildByValue(TNode *p_tnode, char *type, void *value); +int removeChildByValue(TNode *p_tnode, int type, void *value); int TreeThroughDown(Tree *p_tree, int(*func)(TNode *, unsigned long long height)); int TreeThroughUp(Tree *p_tree, int(*func)(TNode *, unsigned long long height)); int TreeTravel(Tree *p_tree, int(*func)(TNode *, unsigned long long height)); -static int _dogetChildById(const char *type, void *value); -static int _dogetChildByValue(const char *type, void *value); -static int _doreleaseTree(TNode *p_tnode, unsigned long long height); -static int _doTreeThroughDown(TNode *p_tnode, int height, int(*func)(TNode *, unsigned long long height)); -static int _doTreeThroughUp(TNode *p_tnode, int height, int(*func)(TNode *, unsigned long long height)); +int _dogetChildById(int type, void *value); +int _dogetChildByValue(int type, void *value); +int _doreleaseTree(TNode *p_tnode, unsigned long long height); +int _doTreeThroughDown(TNode *p_tnode, int height, int(*func)(TNode *, unsigned long long height)); +int _doTreeThroughUp(TNode *p_tnode, int height, int(*func)(TNode *, unsigned long long height)); int releaseTree(Tree *p_tree); int releaseOnlyTree(Tree *p_tree); -int releaseTNode(TNode *p_tnode); -static int releaseOnlyTNode(TNode *p_tnode); +int releaseTNode(TNode *p_tnode); +int releaseOnlyTNode(TNode *p_tnode); int setRoot(Tree *p_tree, TNode *p_tnode); -static char *target_type; +static int target_type; static void *target_value; static TNode *target_value_value; @@ -83,4 +73,3 @@ static int if_safeModeForTree; #endif ->>>>>>> 30b15314d8173f7cdfb24ab7f9250435ae2db90c diff --git a/tree/tree_expand.c b/tree/tree_expand.c index 353526a..0ef44a2 100644 --- a/tree/tree_expand.c +++ b/tree/tree_expand.c @@ -4,7 +4,7 @@ TNode *tnodeWithInt(int temp) { TNode *p_tnode = initTNode(); int *p_temp = (int *)malloc(sizeof(int)); *p_temp = temp; - initMallocValueForTNode(p_tnode, "int", p_temp); + initMallocValueForTNode(p_tnode, INT, p_temp); return p_tnode; } @@ -12,46 +12,46 @@ TNode *tnodeWithDouble(double temp) { TNode *p_tnode = initTNode(); double *p_temp = (double *)malloc(sizeof(double)); *p_temp = temp; - initMallocValueForTNode(p_tnode, "double", p_temp); + initMallocValueForTNode(p_tnode, DOUBLE, p_temp); return p_tnode; } TNode *tnodeWithString(char *temp) { TNode *p_tnode = initTNode(); char *p_temp = (char *)malloc(sizeof(temp)); - strcpy_s(p_temp, sizeof(p_temp), temp); - initMallocValueForTNode(p_tnode, "double", p_temp); + strcpy(p_temp, temp); + initMallocValueForTNode(p_tnode, STRING, p_temp); return p_tnode; } TNode *tnodeWithPointer(void *temp) { TNode *p_tnode = initTNode(); - initMallocValueForTNode(p_tnode, "pointer", temp); + initMallocValueForTNode(p_tnode, POINTER, temp); return p_tnode; } int getValueByIntForTree(TNode *p_tnode) { - if (!strcmp(p_tnode->type, "int")) { + if (p_tnode->type == INT) { return *(int *)p_tnode->value; } return -1; } double getValueByDoubleForTree(TNode *p_tnode) { - if (!strcmp(p_tnode->type, "double")) { + if (p_tnode->type == DOUBLE) { return *(double *)p_tnode->value; } return -1; } char *getValueByStringForTree(TNode *p_tnode) { - if (!strcmp(p_tnode->type, "string")) { + if (p_tnode->type == STRING) { return (char *)p_tnode->value; } return NULL; } void *getValueByPointerForTree(TNode *p_tnode) { - if (!strcmp(p_tnode->type, "pointer")) { + if (p_tnode->type == POINTER) { return p_tnode->value; } return NULL; @@ -70,17 +70,17 @@ int printTNode(TNode *p_tnode, int priority) { if (p_tnode->if_malloc) { printf("YES\n"); for (i = 0; i < priority + 1; i++) printf(" "); - printf("Value(type: %s): ", p_tnode->type); - if (!strcmp(p_tnode->type, "int")) { + printf("Value(type: %d): ", p_tnode->type); + if (p_tnode->type == INT) { printf("%d\n", *(int *)(p_tnode->value)); } - else if (!strcmp(p_tnode->type, "double")) { + else if (p_tnode->type == DOUBLE) { printf("%a\n", *(double *)(p_tnode->value)); } - else if (!strcmp(p_tnode->type, "string")) { + else if (p_tnode->type == STRING) { printf("%s\n", (char *)(p_tnode->value)); } - else if (!strcmp(p_tnode->type, "pointer")) { + else if (p_tnode->type == POINTER) { printf("%p\n", (char *)(p_tnode->value)); } } @@ -108,17 +108,17 @@ int printTNodeWithHome(TNode *p_tnode,int priority) { if (p_tnode->if_malloc) { printf("YES\n"); for (i = 0; i < priority + 1; i++) printf(" "); - printf("Value(type: %s): ", p_tnode->type); - if (!strcmp(p_tnode->type, "int")) { + printf("Value(type: %d): ", p_tnode->type); + if (p_tnode->type == INT) { printf("%d\n", *(int *)(p_tnode->value)); } - else if (!strcmp(p_tnode->type, "double")) { + else if (p_tnode->type == DOUBLE) { printf("%a\n", *(double *)(p_tnode->value)); } - else if (!strcmp(p_tnode->type, "string")) { + else if (p_tnode->type == STRING) { printf("%s\n", (char *)(p_tnode->value)); } - else if (!strcmp(p_tnode->type, "pointer")) { + else if (p_tnode->type == POINTER) { printf("%p\n", (char *)(p_tnode->value)); } } @@ -164,17 +164,17 @@ int printTNodeWithFamily(TNode *p_tnode, int priority) { if (p_tnode->if_malloc) { printf("YES\n"); for (i = 0; i < priority + 1; i++) printf(" "); - printf("Value(type: %s): ", p_tnode->type); - if (!strcmp(p_tnode->type, "int")) { + printf("Value(type: %d): ", p_tnode->type); + if (p_tnode->type == INT) { printf("%d\n", *(int *)(p_tnode->value)); } - else if (!strcmp(p_tnode->type, "double")) { + else if (p_tnode->type == DOUBLE) { printf("%a\n", *(double *)(p_tnode->value)); } - else if (!strcmp(p_tnode->type, "string")) { + else if (p_tnode->type == STRING) { printf("%s\n", (char *)(p_tnode->value)); } - else if (!strcmp(p_tnode->type, "pointer")) { + else if (p_tnode->type == POINTER) { printf("%p\n", (char *)(p_tnode->value)); } } @@ -211,4 +211,4 @@ int printTree(Tree *p_tree) { printf("Tree(id: %llu)",p_tree->id); printTNodeWithFamily(p_tree->root,0); return 0; -} \ No newline at end of file +} diff --git a/type/type.h b/type/type.h new file mode 100644 index 0000000..199e088 --- /dev/null +++ b/type/type.h @@ -0,0 +1,21 @@ +// +// type.h +// ZE-Standard-Libraries +// +// Created by 胡一兵 on 2018/7/23. +// Copyright © 2018年 ZE. All rights reserved. +// + +#ifndef type_h +#define type_h + +#define VOID 0 +#define INT 1 +#define DOUBLE 2 +#define STRING 3 +#define POINTER 4 +#define LIST 5 + + + +#endif /* type_h */ From fbb2a97ce57017eb831cbfe1f595642d773c76e4 Mon Sep 17 00:00:00 2001 From: Saturneic Date: Mon, 23 Jul 2018 13:47:31 +0800 Subject: [PATCH 27/31] Fix and add. --- .../xcdebugger/Breakpoints_v2.xcbkptlist | 32 +++++++++++++++++++ list/list_expand.c | 11 +++++++ list/list_expand.h | 2 ++ tree/tree_expand.c | 15 ++++++++- tree/tree_expand.h | 3 ++ 5 files changed, 62 insertions(+), 1 deletion(-) diff --git a/ZE-Standard-Libraries.xcodeproj/xcuserdata/huyibing.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist b/ZE-Standard-Libraries.xcodeproj/xcuserdata/huyibing.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist index d16736f..f56e272 100644 --- a/ZE-Standard-Libraries.xcodeproj/xcuserdata/huyibing.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist +++ b/ZE-Standard-Libraries.xcodeproj/xcuserdata/huyibing.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist @@ -147,5 +147,37 @@ landmarkType = "9"> + + + + + + + + diff --git a/list/list_expand.c b/list/list_expand.c index 33f21b5..287658a 100644 --- a/list/list_expand.c +++ b/list/list_expand.c @@ -348,4 +348,15 @@ List *m_findByStringForNode(List* p_list, char *temp) { List *m_findByPointerForNode(List* p_list, void *temp) { return mply_findByValue(p_list, POINTER, (void *)temp); +} + +unsigned long long calListMemory(List * p_list){ + Node *p_node = p_list->head; + unsigned long long nodes_size = 0LL; + unsigned long long list_size = sizeof(p_list); + while(p_node != NULL){ + nodes_size += sizeof(p_node) + sizeof(*p_node->value); + p_node = p_node->next; + } + return list_size + nodes_size; } diff --git a/list/list_expand.h b/list/list_expand.h index a9d210f..18ba83e 100644 --- a/list/list_expand.h +++ b/list/list_expand.h @@ -36,5 +36,7 @@ char *getByStringForNode(Node *);//直接得到节点的值 void *getByPointerForNode(Node *);//直接得到节点的值 unsigned long long getIndexByNode(List *p_list,Node *p_node); int listThrough(List *p_list, int (*p_func)(int , void *));//遍历链表并不断调用目标函数。目标函数将接受节点储存值的指针及其类型。 + +unsigned long long calListMemory(List *); #endif diff --git a/tree/tree_expand.c b/tree/tree_expand.c index 0ef44a2..1f30a1f 100644 --- a/tree/tree_expand.c +++ b/tree/tree_expand.c @@ -211,4 +211,17 @@ int printTree(Tree *p_tree) { printf("Tree(id: %llu)",p_tree->id); printTNodeWithFamily(p_tree->root,0); return 0; -} +} + +static unsigned long long tnodes_size = 0LL; + +unsigned long long calTreeMemory(Tree *p_tree){ + tnodes_size = 0LL; + TreeThroughDown(p_tree, _doCalTreeMemory); + return sizeof(p_tree) + tnodes_size; +} + +int _doCalTreeMemory(TNode *p_tnode, unsigned long long height){ + tnodes_size += sizeof(p_tnode) + sizeof(*p_tnode->value); + return 0; +} diff --git a/tree/tree_expand.h b/tree/tree_expand.h index d8d882a..a4236a2 100644 --- a/tree/tree_expand.h +++ b/tree/tree_expand.h @@ -17,5 +17,8 @@ int printTree(Tree *p_tree); int printTNodeWithHome(TNode *p_tnode, int priority); int printTNodeWithFamily(TNode *p_tnode, int priority); int printTNode(TNode *p_tnode, int priority); + +unsigned long long calTreeMemory(Tree *); +int _doCalTreeMemory(TNode *p_tnode, unsigned long long height); #endif From 5ae6717bfc1788568d8e500ae54e4ea6565a9841 Mon Sep 17 00:00:00 2001 From: Saturneic Date: Wed, 25 Jul 2018 22:10:09 +0800 Subject: [PATCH 28/31] Fixed --- id/id.c | 30 ++++++++++++++++++++++++++++++ id/id.h | 22 ++++++++++++++++++++++ list/list.c | 15 --------------- list/list.h | 5 +---- tree/tree_expand.h | 3 +++ type/type.h | 2 ++ 6 files changed, 58 insertions(+), 19 deletions(-) create mode 100644 id/id.c create mode 100644 id/id.h diff --git a/id/id.c b/id/id.c new file mode 100644 index 0000000..d2c860c --- /dev/null +++ b/id/id.c @@ -0,0 +1,30 @@ +// +// id.c +// ZE-Standard-Libraries +// +// Created by 胡一兵 on 2018/7/25. +// Copyright © 2018年 ZE. All rights reserved. +// + +#include "id.h" + +void init_rand(void) { + srand((unsigned)time(NULL)); +} + +unsigned long long getId(void) { + int i; + unsigned long long id = 0; + id = ((rand() % 9) + 1); + for (i = 0; i < 15; i++) { + id *= 10; + id += rand() % 10; + } + return id; +} + +char *getS_id(void){ + + return NULL; +} + diff --git a/id/id.h b/id/id.h new file mode 100644 index 0000000..fe9981a --- /dev/null +++ b/id/id.h @@ -0,0 +1,22 @@ +// +// id.h +// ZE-Standard-Libraries +// +// Created by 胡一兵 on 2018/7/25. +// Copyright © 2018年 ZE. All rights reserved. +// + +#ifndef id_h +#define id_h + +#include +#include + +/*有关id的函数*/ +void init_rand(void); +unsigned long long getId(void); + +/*有关s_id函数*/ +char *getS_id(void); + +#endif /* id_h */ diff --git a/list/list.c b/list/list.c index 4afc44d..a4a2a08 100644 --- a/list/list.c +++ b/list/list.c @@ -121,21 +121,6 @@ int initMallocValueForNode(Node *p_node, int type, void *p_value) { return 0; } -void init_rand(void) { - srand((unsigned)time(NULL)); -} - -unsigned long long getId(void) { - int i; - unsigned long long id = 0; - id = ((rand() % 9) + 1); - for (i = 0; i < 15; i++) { - id *= 10; - id += rand() % 10; - } - return id; -} - int insertInHead(List *p_list, Node *p_node) { if (isListEmpty(p_list)) { p_list->head = p_node; diff --git a/list/list.h b/list/list.h index defec7f..f9496de 100644 --- a/list/list.h +++ b/list/list.h @@ -6,6 +6,7 @@ #include #include #include "../type/type.h" +#include "../id/id.h" typedef struct Node{ unsigned long long id;//唯一标识符 @@ -34,10 +35,6 @@ Node *initNode(void); int initMallocValueForNode(Node *,int,void *);//赋予已分配内存的值,并标明类型 -/*有关id的函数*/ -void init_rand(void); -unsigned long long getId(void); - /*插入函数*/ int insertInHead(List *p_list, Node *p_node); int insertInTail(List *p_list, Node *p_node); diff --git a/tree/tree_expand.h b/tree/tree_expand.h index a4236a2..bec0086 100644 --- a/tree/tree_expand.h +++ b/tree/tree_expand.h @@ -20,5 +20,8 @@ int printTNode(TNode *p_tnode, int priority); unsigned long long calTreeMemory(Tree *); int _doCalTreeMemory(TNode *p_tnode, unsigned long long height); + +List *treeToList(Tree *p_tree); + #endif diff --git a/type/type.h b/type/type.h index 199e088..cd7a83c 100644 --- a/type/type.h +++ b/type/type.h @@ -15,6 +15,8 @@ #define STRING 3 #define POINTER 4 #define LIST 5 +#define STACK 6 +#define TREE 7 From 667e48801d4ec21a3012753331e662ad4a4aa817 Mon Sep 17 00:00:00 2001 From: Saturneic Date: Mon, 30 Jul 2018 17:45:33 +0800 Subject: [PATCH 29/31] Add and Fixed. --- communicate/communicate.c | 9 ++ communicate/communicate.h | 14 +++ graph/graph.c | 2 +- graph/graph.h | 4 +- id/id.c | 209 +++++++++++++++++++++++++++++++++++++- id/id.h | 21 +++- list/list.c | 18 ++-- list/list.h | 17 ++-- list/list_expand.c | 2 +- list/list_expand.h | 2 +- stack/stack.c | 4 +- stack/stack.h | 10 +- test.c | 8 +- tree/tree.c | 46 +++++---- tree/tree.h | 30 +++--- type/type.h | 13 +++ 16 files changed, 344 insertions(+), 65 deletions(-) create mode 100644 communicate/communicate.c create mode 100644 communicate/communicate.h diff --git a/communicate/communicate.c b/communicate/communicate.c new file mode 100644 index 0000000..97e91a1 --- /dev/null +++ b/communicate/communicate.c @@ -0,0 +1,9 @@ +// +// communicate.c +// ZE-Standard-Libraries +// +// Created by 胡一兵 on 2018/7/25. +// Copyright © 2018年 ZE. All rights reserved. +// + +#include "communicate.h" diff --git a/communicate/communicate.h b/communicate/communicate.h new file mode 100644 index 0000000..4dde066 --- /dev/null +++ b/communicate/communicate.h @@ -0,0 +1,14 @@ +// +// communicate.h +// ZE-Standard-Libraries +// +// Created by 胡一兵 on 2018/7/25. +// Copyright © 2018年 ZE. All rights reserved. +// + +#ifndef communicate_h +#define communicate_h + + + +#endif /* communicate_h */ diff --git a/graph/graph.c b/graph/graph.c index e43cd57..e8b6b5e 100644 --- a/graph/graph.c +++ b/graph/graph.c @@ -1 +1 @@ -#include "graph.h" \ No newline at end of file +#include "graph.h" diff --git a/graph/graph.h b/graph/graph.h index c1db03d..702dc11 100644 --- a/graph/graph.h +++ b/graph/graph.h @@ -4,14 +4,14 @@ #include "../list/list_expand.h" typedef struct GNode{ - unsigned long long id; + SID *s_id; void *value; List *routes; int if_setValue; }GNode; typedef struct route{ - unsigned long long id; + SID *s_id; double distance; int if_setValue; GNode from, to; diff --git a/id/id.c b/id/id.c index d2c860c..e8a756d 100644 --- a/id/id.c +++ b/id/id.c @@ -23,8 +23,211 @@ unsigned long long getId(void) { return id; } -char *getS_id(void){ - - return NULL; +SID *initS_id(unsigned int deep_level){ + SID *p_sid = (SID *)malloc(sizeof(SID)); + p_sid->type = VOID; + p_sid->deep = deep_level; + p_sid->value = NULL; + p_sid->value_deeper = NULL; + p_sid->value_deepest = NULL; + if (deep_level > 0) p_sid->value = (unsigned int (*)[DEEPC_LEN])malloc(sizeof(unsigned int)*DEEPC_LEN); + if (deep_level > 1) p_sid->value_deeper = (unsigned int (*)[DEEPB_LEN])malloc(sizeof(unsigned int)*DEEPB_LEN); + if (deep_level > 2) p_sid->value_deepest = (unsigned int (*)[DEEPA_LEN])malloc(sizeof(unsigned int)*DEEPA_LEN); + return p_sid; } +SID *getS_id(unsigned int type, unsigned int deep_level){ + SID *p_sid = (SID *)malloc(sizeof(SID)); + p_sid->type = type; + p_sid->deep = deep_level; + p_sid->value = NULL; + p_sid->value_deeper = NULL; + p_sid->value_deepest = NULL; + if(deep_level > 0){ + p_sid->value = (unsigned int (*)[DEEPC_LEN])malloc(sizeof(unsigned int)*DEEPC_LEN); + for(int i = 0; i < DEEPC_LEN; i++) (*p_sid->value)[i] = rand()%65535; + if(deep_level > 1){ + p_sid->value_deeper = (unsigned int (*)[DEEPB_LEN])malloc(sizeof(unsigned int)*DEEPB_LEN); + for(int i = 0; i < DEEPB_LEN; i++) (*p_sid->value_deeper)[i] = rand()%65535; + } + if (deep_level > 2) { + p_sid->value_deepest = (unsigned int (*)[DEEPA_LEN])malloc(sizeof(unsigned int)*DEEPA_LEN); + for(int i = 0; i < DEEPA_LEN; i++) (*p_sid->value_deepest)[i] = rand()%65535; + } + } + + return p_sid; +} + +int fitS_id(const SID *fs_id, const SID *ss_id){ + if(fs_id->type == ss_id->type){ + if(fs_id->deep == ss_id->deep){ + if (fs_id->deep > 0) + for(int i = 0; i < DEEPC_LEN; i++){ + if((*fs_id->value)[i] == (*ss_id->value)[i]) continue; + else if((*fs_id->value)[i] > (*ss_id->value)[i]) return 1; + else return -1; + } + if (fs_id->deep > 1) + for(int i = 0; i < DEEPB_LEN; i++){ + if((*fs_id->value_deeper)[i] == (*ss_id->value_deeper)[i]) continue; + else if((*fs_id->value_deeper)[i] > (*ss_id->value_deeper)[i]) return 1; + else return -1; + } + if (fs_id->deep > 2) + for(int i = 0; i < DEEPA_LEN; i++){ + if((*fs_id->value_deepest)[i] == (*ss_id->value_deepest)[i]) continue; + else if((*fs_id->value_deepest)[i] > (*ss_id->value_deepest)[i]) return 1; + else return -1; + } + } + else{ + if(fs_id->deep > ss_id->deep) return 1; + else return -1; + } + } + else{ + if (fs_id->type > ss_id->type) return 1; + else return -1; + } + return 0; +} + +int simFitS_id(const SID *fs_id, const SID *ss_id){ + return !fitS_id(fs_id, ss_id); +} + +char *s_idToASCIIString(const SID *s_id){ + char *string = NULL; + int deep_len = 0, temp, buff_count, string_count; + unsigned int buff[DATA_BIT]; + if(s_id->deep > 0){ + if (s_id->deep == DEEPC){ + string = (char *) malloc(sizeof(char) * (DEEPC_LEN + 1) * DATA_BIT + 1); + deep_len = DEEPC_LEN + 1; + deep_len *= DATA_BIT; + } + else if (s_id->deep == DEEPB){ + string = (char *) malloc(sizeof(char) * (DEEPC_LEN + DEEPB_LEN + 1) * DATA_BIT + 1); + deep_len = DEEPC_LEN + DEEPB_LEN + 1; + deep_len *= DATA_BIT; + } + else{ + string = (char *)malloc(sizeof(char) * (DEEPC_LEN + DEEPB_LEN + DEEPA_LEN + 1) * DATA_BIT + 1); + deep_len = DEEPC_LEN + DEEPB_LEN + DEEPA_LEN + 1; + deep_len *= DATA_BIT; + } + string[deep_len] = '\0'; + temp = s_id->type; + buff_count = DATA_BIT - 1; + for (int i = 0; i < DATA_BIT; i++) buff[i] = 0; + while(buff_count >= 0){ + buff[buff_count] = temp % 10; + string[buff_count] = buff[buff_count] + 48; + temp /= 10; + buff_count--; + } + deep_len -= DATA_BIT; + for(int i = 0; i < DEEPC_LEN; i++){ + temp = (*s_id->value)[i]; + for (int i = 0; i < DATA_BIT; i++) buff[i] = 0; + string_count = TYPE_LEN + (i) * 5; + buff_count = DATA_BIT - 1; + while (buff_count >= 0) { + buff[buff_count] = temp % 10; + temp /= 10; + buff_count--; + } + for(int i = DATA_BIT - 1; i >= 0; i--) string[string_count + i] = buff[i] + 48; + } + deep_len -= DEEPC_LEN * DATA_BIT; + if(deep_len > 0) + for(int i = 0; i < DEEPB_LEN; i++){ + temp = (*s_id->value_deeper)[i]; + for (int i = 0; i < DATA_BIT; i++) buff[i] = 0; + string_count = TYPE_LEN + DEEPC_LEN * DATA_BIT + (i) * DATA_BIT; + buff_count = DATA_BIT - 1; + while (buff_count >= 0) { + buff[buff_count] = temp % 10; + temp /= 10; + buff_count--; + } + for(int i = DATA_BIT - 1; i >= 0; i--) string[string_count + i] = buff[i] + 48; + } + + deep_len -= DEEPB_LEN * DATA_BIT; + if(deep_len > 0) + for(int i = 0; i < DEEPA_LEN; i++){ + temp = (*s_id->value_deepest)[i]; + for (int i = 0; i < DATA_BIT; i++) buff[i] = 0; + string_count = TYPE_LEN + (DEEPC_LEN + DEEPB_LEN) * DATA_BIT + (i) * DATA_BIT; + buff_count = DATA_BIT - 1; + while (buff_count >= 0) { + buff[buff_count] = temp % 10; + string[string_count] = buff[buff_count] + 48; + temp /= 10; + buff_count--; + } + for(int i = DATA_BIT - 1; i >= 0; i--) string[string_count + i] = buff[i] + 48; + } + printf("%s",string); + return string; + } + else{ + return NULL; + } + +} +SID *asciiStringToS_id(const char *string){ + SID *s_id = NULL; + unsigned long long string_len = strlen(string); + unsigned int buff[string_len - 1]; + for(int i = 0; i < string_len; i++){ + buff[i] = string[i] - 48; + } + if (string_len == 25) s_id = initS_id(1); + else if (string_len == 65) s_id = initS_id(2); + else if (string_len == 225) s_id = initS_id(3); + else return NULL; + + + + for (int i = 0; i < 5; i++){ + s_id->type += buff[i] ; + s_id->type *= 10; + } + s_id->type /= 10; + + if (string_len >= 25){ + for(int i = 0; i < DEEPC_LEN; i++){ + (*s_id->value)[i] = 0; + for (int j = 0; j < 5; j++){ + (*s_id->value)[i] += (int)buff[5 + i * 5 + j]; + (*s_id->value)[i] *= 10; + } + (*s_id->value)[i] /= 10; + } + } + + if (string_len >= 65){ + for(int i = 0; i < DEEPB_LEN; i++){ + (*s_id->value_deeper)[i] = 0; + for (int j = 0; j < 5; j++){ + (*s_id->value_deeper)[i] += buff[25 + i * 5 + j]; + (*s_id->value_deeper)[i] *= 10; + } + (*s_id->value_deeper)[i] /= 10; + } + } + if (string_len >= 225){ + for(int i = 0; i < DEEPA_LEN; i++){ + (*s_id->value_deepest)[i] = 0; + for (int j = 0; j < 5; j++){ + (*s_id->value_deepest)[i] += buff[65 + i * 5 + j]; + (*s_id->value_deepest)[i] *= 10; + } + (*s_id->value_deepest)[i] /= 10; + } + } + return s_id; +} diff --git a/id/id.h b/id/id.h index fe9981a..894cd3c 100644 --- a/id/id.h +++ b/id/id.h @@ -9,14 +9,33 @@ #ifndef id_h #define id_h +#include #include +#include #include +#include "../type/type.h" + +typedef struct s_id{ + unsigned int type; + unsigned int (*value)[DEEPC_LEN];//4 + unsigned int (*value_deeper)[DEEPB_LEN];//8 + unsigned int (*value_deepest)[DEEPA_LEN];//32 + unsigned int deep; +}SID; /*有关id的函数*/ void init_rand(void); unsigned long long getId(void); /*有关s_id函数*/ -char *getS_id(void); +SID *getS_id(unsigned int type ,unsigned int deep_level); + +int fitS_id(const SID *fs_id, const SID *ss_id); +int simFitS_id(const SID *fs_id, const SID *ss_id); + +char *s_idToASCIIString(const SID *s_id); +SID *asciiStringToS_id(const char *string); + +SID *initS_id(unsigned int deep_level); #endif /* id_h */ diff --git a/list/list.c b/list/list.c index a4a2a08..96b45ac 100644 --- a/list/list.c +++ b/list/list.c @@ -83,6 +83,7 @@ Node *initNode(void) { Node *p_node = (Node *)malloc(sizeof(Node)); Node *prec_node = NULL; p_node->id = getId(); + p_node->s_id = getS_id(LIST_NODE, 2); p_node->if_malloc = 0; p_node->next = NULL; p_node->last = NULL; @@ -101,6 +102,7 @@ List *initList(void) { Node *p_node; List *p_list = (List *)malloc(sizeof(List)); p_list->id = getId(); + p_list->s_id = getS_id(LIST, 1); p_list->head = NULL; p_list->tail = NULL; p_list->length = 0; @@ -114,7 +116,7 @@ List *initList(void) { return p_list; } -int initMallocValueForNode(Node *p_node, int type, void *p_value) { +int initMallocValueForNode(Node *p_node, unsigned int type, void *p_value) { p_node->if_malloc = 1; p_node->type = type; p_node->value = p_value; @@ -212,12 +214,12 @@ unsigned long long len(List *p_list) { return p_list->length; } -int removeById(List *p_list, unsigned long long id) { +int removeById(List *p_list, const SID *s_id) { Node *tmp = p_list->head; if (isListEmpty(p_list)) return -1; do { - if (tmp->id == id) { + if (simFitS_id(tmp->s_id, s_id)) { if (tmp != p_list->head) { tmp->last->next = tmp->next; } @@ -298,13 +300,13 @@ int popFromTail(List *p_list) { } /*该函数算法需要改进*/ -Node *findByIdForNode(List *p_list, const unsigned long long id) { +Node *findByIdForNode(List *p_list, const SID *s_id) { Node *ph_node = p_list->head; Node *pt_node = p_list->tail; int direction = 0; while (ph_node != pt_node) { if (direction == 0) { - if (ph_node->id == id) { + if (simFitS_id(ph_node->s_id, s_id)) { return ph_node; } else { @@ -313,7 +315,7 @@ Node *findByIdForNode(List *p_list, const unsigned long long id) { direction = 1; } else { - if (pt_node->id == id) { + if (simFitS_id(pt_node->s_id, s_id)) { return pt_node; } else { @@ -325,7 +327,7 @@ Node *findByIdForNode(List *p_list, const unsigned long long id) { } -Node *findByValue(List *p_list, int type, const void *value) { +Node *findByValue(List *p_list, unsigned int type, const void *value) { Node *p_node = p_list->head; while (p_node != NULL) { if (p_node->type != type) { @@ -360,7 +362,7 @@ Node *findByValue(List *p_list, int type, const void *value) { return NULL; } -List *mply_findByValue(List *p_list, int type, const void *value) { +List *mply_findByValue(List *p_list, unsigned int type, const void *value) { List *f_list = initList(); Node *p_node = p_list->head; while (p_node != NULL) { diff --git a/list/list.h b/list/list.h index f9496de..cef010e 100644 --- a/list/list.h +++ b/list/list.h @@ -10,9 +10,11 @@ typedef struct Node{ unsigned long long id;//唯一标识符 + SID *s_id; void *value; - int if_malloc;//记录是否已经初始化值 - int type;//记录值的类型 + _Bool if_malloc;//记录是否已经初始化值 + _Bool if_sid; + unsigned int type;//记录值的类型 struct Node *next; struct Node *last; } Node; @@ -20,6 +22,7 @@ typedef struct Node{ typedef struct List{ unsigned long long id;//唯一标识符 + SID *s_id; Node *head; Node *tail; unsigned long long length;//链表长度 @@ -33,7 +36,7 @@ int releaseAllForNode(void);//安全模式最后调用的函数 List *initList(void); Node *initNode(void); -int initMallocValueForNode(Node *,int,void *);//赋予已分配内存的值,并标明类型 +int initMallocValueForNode(Node *,unsigned int,void *);//赋予已分配内存的值,并标明类型 /*插入函数*/ int insertInHead(List *p_list, Node *p_node); @@ -46,16 +49,16 @@ int exchangeLocation(Node *p_node,Node *t_node); Node *copyNode(Node *); /*移除函数*/ -int removeById(List *p_list, unsigned long long id); +int removeById(List *p_list, const SID *s_id); int removeByNode(List *p_list, Node *p_node); int popFromHead(List *p_list); int popFromTail(List *p_list); unsigned long long len(List *p_list);//查看链表的长度 -Node *findByIdForNode(List *p_list, const unsigned long long id);//通过id查找目标链表中的匹配节点 -Node *findByValue(List *p_list, int type, const void *value);//通过值来查找目标链表中的匹配节点 -List *mply_findByValue(List *p_list, int type, const void *value);//寻找多个值匹配的节点 +Node *findByIdForNode(List *p_list, const SID *s_id);//通过id查找目标链表中的匹配节点 +Node *findByValue(List *p_list, unsigned int type, const void *value);//通过值来查找目标链表中的匹配节点 +List *mply_findByValue(List *p_list, unsigned int type, const void *value);//寻找多个值匹配的节点 int releaseList(List *p_list);//释放List并可选择是否释放中所有的其中的Node int releaseListForSingle(List *p_list);//单独释放List diff --git a/list/list_expand.c b/list/list_expand.c index 287658a..d4b647a 100644 --- a/list/list_expand.c +++ b/list/list_expand.c @@ -50,7 +50,7 @@ Node *findByIndexForNode(List *p_list, unsigned long long m_index) { return p_node; } -int listThrough(List *p_list, int(*p_func)(int, void *)) { +int listThrough(List *p_list, int(*p_func)(unsigned int, void *)) { Node *p_node = p_list->head; while (p_node != NULL) { if (p_node->if_malloc == 1) { diff --git a/list/list_expand.h b/list/list_expand.h index 18ba83e..4abcd23 100644 --- a/list/list_expand.h +++ b/list/list_expand.h @@ -35,7 +35,7 @@ double getByDoubleForNode(Node *);//直接得到节点的值 char *getByStringForNode(Node *);//直接得到节点的值 void *getByPointerForNode(Node *);//直接得到节点的值 unsigned long long getIndexByNode(List *p_list,Node *p_node); -int listThrough(List *p_list, int (*p_func)(int , void *));//遍历链表并不断调用目标函数。目标函数将接受节点储存值的指针及其类型。 +int listThrough(List *p_list, int (*p_func)(unsigned int type, void *value));//遍历链表并不断调用目标函数。目标函数将接受节点储存值的指针及其类型。 unsigned long long calListMemory(List *); diff --git a/stack/stack.c b/stack/stack.c index 5682201..9689f86 100644 --- a/stack/stack.c +++ b/stack/stack.c @@ -3,6 +3,7 @@ Stack *initStack(void) { Stack *p_stack = (Stack *)malloc(sizeof(Stack)); p_stack->id = getId(); + p_stack->s_id = getS_id(STACK, 1); p_stack->length = 0; p_stack->top = NULL; return p_stack; @@ -11,6 +12,7 @@ Stack *initStack(void) { SNode *initSNode(void) { SNode *p_snode = (SNode *)malloc(sizeof(SNode)); p_snode->id = getId(); + p_snode->s_id = getS_id(STACK_NODE, 2); p_snode->if_malloc = 0; p_snode->next = NULL; p_snode->value = NULL; @@ -60,7 +62,7 @@ int releaseSNode(SNode *p_snode) { return 0; } -int initMallocValueForSNode(SNode *p_snode, int type, void *value) { +int initMallocValueForSNode(SNode *p_snode, unsigned int type, void *value) { p_snode->if_malloc = 1; p_snode->type = type; p_snode->value = value; diff --git a/stack/stack.h b/stack/stack.h index 4dfd7a6..9581f5b 100644 --- a/stack/stack.h +++ b/stack/stack.h @@ -6,21 +6,25 @@ typedef struct stack_node{ unsigned long long id; - int if_malloc; - int type; + SID *s_id; + _Bool if_malloc; + _Bool if_sid; + unsigned int type; void *value; struct stack_node *next; } SNode; typedef struct stack{ unsigned long long id; + SID *s_id; unsigned long long length; SNode *top; + _Bool if_sid; } Stack; Stack *initStack(void); SNode *initSNode(void); -int initMallocValueForSNode(SNode *p_snode, int type, void *value); +int initMallocValueForSNode(SNode *p_snode, unsigned int type, void *value); SNode *popStack(Stack *p_stack); int pushStack(Stack *p_stack, SNode *p_snode); diff --git a/test.c b/test.c index 210d23f..c7a718b 100644 --- a/test.c +++ b/test.c @@ -3,7 +3,6 @@ int list(void) { List *t_list, *m_list;; - init_rand(); safeModeForNode(1); t_list = initList(); @@ -83,7 +82,12 @@ int stack(void) { int main(int argc, char **argv) { - tree(); + //tree(); + init_rand(); + SID *p_sid = getS_id(LIST_NODE, 3); + char *string = s_idToASCIIString(p_sid); + SID *t_sid = asciiStringToS_id(string); + int if_same = simFitS_id(p_sid, t_sid); getchar(); return 0; } diff --git a/tree/tree.c b/tree/tree.c index 5171631..519df76 100644 --- a/tree/tree.c +++ b/tree/tree.c @@ -1,7 +1,7 @@ #include"tree.h" -static unsigned long long target_id = 0; -static TNode *target_value_id = NULL; +static SID *target_sid = NULL; +static TNode *target_value_sid = NULL; static int if_safeModeForTree = 0; int safeModeForTree(int ifon) { @@ -31,7 +31,8 @@ int safeModeForTree(int ifon) { TNode *initTNode(void) { Node *s_node; TNode *p_tnode = (TNode *)malloc(sizeof(TNode)); - p_tnode->id = getId(); + p_tnode->id = getId(); + p_tnode->s_id = getS_id(TREE_NODE, 2); p_tnode->child_num = 0; p_tnode->father = NULL; p_tnode->if_malloc = 0; @@ -60,7 +61,8 @@ TNode *initTNode(void) { Tree *initTree(void) { Node *s_node; Tree *p_tree = (Tree *)malloc(sizeof(Tree)); - p_tree->id = getId(); + p_tree->id = getId(); + p_tree->s_id = getS_id(TREE, 1); p_tree->root = NULL; if (if_safeModeForTree) { if (if_safeModeForNode) { @@ -80,7 +82,7 @@ Tree *initTree(void) { return p_tree; } -int *initMallocValueForTNode(TNode *p_tnode, int type, void *value) { +int *initMallocValueForTNode(TNode *p_tnode, unsigned int type, void *value) { p_tnode->type = type; p_tnode->value = value; p_tnode->if_malloc = 1; @@ -144,22 +146,22 @@ int removeChildInRight(TNode *p_tnode) { } -TNode *getChildById(TNode *p_tnode, unsigned long long id) { +TNode *getChildById(TNode *p_tnode, const SID *s_id) { List *p_home = p_tnode->home; - target_id = 0; - target_value_id = NULL; + target_sid = NULL; + target_value_sid = NULL; listThrough(p_home, _dogetChildById); - if (target_value_id != NULL) { - return target_value_id; + if (target_value_sid != NULL) { + return target_value_sid; } return NULL; } -int _dogetChildById(int type, void *value) { +int _dogetChildById(unsigned int type, void *value) { if (type == POINTER) { TNode *p_tode = (TNode *)value; - if (p_tode->id == target_id) { - target_value_id = p_tode; + if (simFitS_id(p_tode->s_id, target_sid)) { + target_value_sid = p_tode; return -1; } } @@ -170,7 +172,7 @@ static int target_type = VOID; static void *target_value = NULL; static TNode *target_value_value = NULL; -TNode *getChildByValue(TNode *p_tnode, int type, void *value) { +TNode *getChildByValue(TNode *p_tnode, unsigned int type, void *value) { List *p_home = p_tnode->home; target_value = value; target_type = type; @@ -182,7 +184,7 @@ TNode *getChildByValue(TNode *p_tnode, int type, void *value) { return NULL; } -int _dogetChildByValue(int type, void *value) { +int _dogetChildByValue(unsigned int type, void *value) { if (type == target_type) { TNode *p_tode = (TNode *)value; if (target_type == INT) { @@ -221,12 +223,12 @@ int _dogetChildByValue(int type, void *value) { return 0; } -int removeChildById(TNode *p_tnode, unsigned long long id) { - TNode *t_tnode = getChildById(p_tnode, id); +int removeChildById(TNode *p_tnode, const SID *s_id) { + TNode *t_tnode = getChildById(p_tnode, s_id); if (t_tnode != NULL) { TNode *p_fnode = t_tnode->father; p_fnode->child_num--; - removeById(p_fnode->home, t_tnode->room->id); + removeById(p_fnode->home, t_tnode->room->s_id); releaseOnlyNode(t_tnode->room); t_tnode->room = NULL; return 0; @@ -234,12 +236,12 @@ int removeChildById(TNode *p_tnode, unsigned long long id) { return -1; } -int removeChildByValue(TNode *p_tnode, int type, void *value) { +int removeChildByValue(TNode *p_tnode, unsigned int type, void *value) { TNode *t_tnode = getChildByValue(p_tnode, type, value); if (t_tnode != NULL) { TNode *p_fnode = t_tnode->father; p_fnode->child_num--; - removeById(p_fnode->home, t_tnode->room->id); + removeById(p_fnode->home, t_tnode->room->s_id); releaseOnlyNode(t_tnode->room); t_tnode->room = NULL; return 0; @@ -282,7 +284,7 @@ int removeChildByIndex(TNode *p_tnode, unsigned long long index) { if (t_tnode != NULL) { TNode *p_fnode = t_tnode->father; p_fnode->child_num--; - removeById(p_fnode->home, t_tnode->room->id); + removeById(p_fnode->home, t_tnode->room->s_id); releaseOnlyNode(t_tnode->room); t_tnode->room = NULL; return 0; @@ -373,7 +375,7 @@ int releaseTNode(TNode *p_tnode) { if (p_tnode->child_num == 0) { releaseList(p_tnode->home); if (p_tnode->father != NULL) { - removeChildById(p_tnode->father, p_tnode->id); + removeChildById(p_tnode->father, p_tnode->s_id); } if (p_tnode->type != POINTER) { if (p_tnode->type == LIST) { diff --git a/tree/tree.h b/tree/tree.h index c2d950f..75afa5d 100644 --- a/tree/tree.h +++ b/tree/tree.h @@ -6,19 +6,23 @@ typedef struct tree_node { - unsigned long long id; + unsigned long long id; + SID *s_id; List *home; struct tree_node *father; Node *room; unsigned long long child_num; - int type; + unsigned int type; void *value; - int if_malloc; + _Bool if_malloc; + _Bool if_sid; }TNode; typedef struct tree { - unsigned long long id; + unsigned long long id; + SID *s_id; + _Bool if_sid; TNode *root; }Tree; @@ -28,7 +32,7 @@ int releaseAllForTree(void); TNode *initTNode(void); Tree *initTree(void); -int *initMallocValueForTNode(TNode *p_tnode, int type, void *value); +int *initMallocValueForTNode(TNode *p_tnode, unsigned int type, void *value); int addChildInLeft(TNode *f_tnode, TNode *c_tnode); int addChildInRight(TNode *f_tnode, TNode *c_tnode); @@ -36,19 +40,19 @@ TNode *getBrotherInLeft(TNode *p_tnode); TNode *getBrotherInRight(TNode *p_node); int removeChildInLeft(TNode *p_tnode); int removeChildInRight(TNode *p_tnode); -TNode *getChildById(TNode *p_tnode, unsigned long long id); -TNode *getChildByValue(TNode *p_tnode, int type, void *value); +TNode *getChildById(TNode *p_tnode, const SID *s_id); +TNode *getChildByValue(TNode *p_tnode, unsigned int type, void *value); TNode *getChildByIndex(TNode *p_tnode, unsigned long long index); unsigned long long getIndexByChild(TNode *f_tnode, TNode *c_tnode); -int removeChildById(TNode *p_tnode, unsigned long long id); +int removeChildById(TNode *p_tnode, const SID *s_id); int removeChildByIndex(TNode *p_tnode, unsigned long long index); -int removeChildByValue(TNode *p_tnode, int type, void *value); +int removeChildByValue(TNode *p_tnode, unsigned int type, void *value); int TreeThroughDown(Tree *p_tree, int(*func)(TNode *, unsigned long long height)); int TreeThroughUp(Tree *p_tree, int(*func)(TNode *, unsigned long long height)); int TreeTravel(Tree *p_tree, int(*func)(TNode *, unsigned long long height)); -int _dogetChildById(int type, void *value); -int _dogetChildByValue(int type, void *value); +int _dogetChildById(unsigned int type, void *value); +int _dogetChildByValue(unsigned int type, void *value); int _doreleaseTree(TNode *p_tnode, unsigned long long height); int _doTreeThroughDown(TNode *p_tnode, int height, int(*func)(TNode *, unsigned long long height)); int _doTreeThroughUp(TNode *p_tnode, int height, int(*func)(TNode *, unsigned long long height)); @@ -64,8 +68,8 @@ static int target_type; static void *target_value; static TNode *target_value_value; -static unsigned long long target_id; -static TNode *target_value_id; +static SID *target_sid; +static TNode *target_value_sid; static List *tree_list; static List *tnode_list; diff --git a/type/type.h b/type/type.h index cd7a83c..3dbb795 100644 --- a/type/type.h +++ b/type/type.h @@ -17,7 +17,20 @@ #define LIST 5 #define STACK 6 #define TREE 7 +#define LIST_NODE 8 +#define TREE_NODE 9 +#define STACK_NODE 10 +#define TYPE_LEN 5 +#define DEEPC 1 +#define DEEPB 2 +#define DEEPA 3 + +#define DEEPC_LEN 4 +#define DEEPB_LEN 8 +#define DEEPA_LEN 32 + +#define DATA_BIT 5 #endif /* type_h */ From 235e53d9b669342c65527c85c3870ef22fc92cc3 Mon Sep 17 00:00:00 2001 From: Saturneic Date: Mon, 30 Jul 2018 18:07:24 +0800 Subject: [PATCH 30/31] Fixed --- id/id.c | 17 +++++++++++++++++ id/id.h | 1 + list/list.c | 12 +++++------- list/list.h | 6 ++---- stack/stack.c | 6 ++---- stack/stack.h | 2 -- tree/tree.c | 16 +++++++--------- tree/tree.h | 6 ++---- 8 files changed, 36 insertions(+), 30 deletions(-) diff --git a/id/id.c b/id/id.c index e8a756d..0aa14fe 100644 --- a/id/id.c +++ b/id/id.c @@ -231,3 +231,20 @@ SID *asciiStringToS_id(const char *string){ } return s_id; } + +int freeS_id(SID *s_id){ + if(s_id->value != NULL){ + free(s_id->value); + s_id->value = NULL; + } + if(s_id->value_deeper != NULL){ + free(s_id->value_deeper); + s_id->value_deeper = NULL; + } + if(s_id->value_deepest != NULL){ + free(s_id->value_deepest); + s_id->value_deepest = NULL; + } + free(s_id); + return 0; +} diff --git a/id/id.h b/id/id.h index 894cd3c..57c8655 100644 --- a/id/id.h +++ b/id/id.h @@ -37,5 +37,6 @@ char *s_idToASCIIString(const SID *s_id); SID *asciiStringToS_id(const char *string); SID *initS_id(unsigned int deep_level); +int freeS_id(SID *s_id); #endif /* id_h */ diff --git a/list/list.c b/list/list.c index 96b45ac..7d2a6d4 100644 --- a/list/list.c +++ b/list/list.c @@ -82,7 +82,6 @@ int releaseAllForNode(void) { Node *initNode(void) { Node *p_node = (Node *)malloc(sizeof(Node)); Node *prec_node = NULL; - p_node->id = getId(); p_node->s_id = getS_id(LIST_NODE, 2); p_node->if_malloc = 0; p_node->next = NULL; @@ -101,7 +100,6 @@ Node *initNode(void) { List *initList(void) { Node *p_node; List *p_list = (List *)malloc(sizeof(List)); - p_list->id = getId(); p_list->s_id = getS_id(LIST, 1); p_list->head = NULL; p_list->tail = NULL; @@ -172,7 +170,7 @@ int releaseNode(Node *p_node) { p_node->next = NULL; p_node->type = VOID; p_node->value = NULL; - p_node->id = 0; + freeS_id(p_node->s_id); p_node->if_malloc = 0; free(p_node); return 0; @@ -196,7 +194,7 @@ int releaseList(List *p_list) { p_list->head = NULL; p_list->tail = NULL; p_list->length = 0; - p_list->id = 0; + freeS_id(p_list->s_id) free(p_list); return 0; } @@ -204,7 +202,7 @@ int releaseList(List *p_list) { int releaseListForSingle(List *p_list) { p_list->head = NULL; p_list->tail = NULL; - p_list->id = 0; + freeS_id(p_list->s_id); p_list->length = 0; free(p_list); return 0; @@ -424,7 +422,7 @@ int exchangeLocation(Node *p_node, Node *t_node) { Node *copyNode(Node *p_node) { Node *t_node = initNode(); - t_node->id = p_node->id; + t_node->s_id = p_node->s_id; t_node->last = p_node->last; t_node->next = p_node->next; t_node->if_malloc = p_node->if_malloc; @@ -450,7 +448,7 @@ List *copyList(List *p_list) { } int releaseOnlyNode(Node *p_node) { - p_node->id = 0; + freeS_id(p_node->s_id); p_node->if_malloc = 0; p_node->last = NULL; p_node->next = NULL; diff --git a/list/list.h b/list/list.h index cef010e..152ec2f 100644 --- a/list/list.h +++ b/list/list.h @@ -9,8 +9,7 @@ #include "../id/id.h" typedef struct Node{ - unsigned long long id;//唯一标识符 - SID *s_id; + SID *s_id;//唯一标识符 void *value; _Bool if_malloc;//记录是否已经初始化值 _Bool if_sid; @@ -21,8 +20,7 @@ typedef struct Node{ typedef struct List{ - unsigned long long id;//唯一标识符 - SID *s_id; + SID *s_id;//唯一标识符 Node *head; Node *tail; unsigned long long length;//链表长度 diff --git a/stack/stack.c b/stack/stack.c index 9689f86..66580bd 100644 --- a/stack/stack.c +++ b/stack/stack.c @@ -2,7 +2,6 @@ Stack *initStack(void) { Stack *p_stack = (Stack *)malloc(sizeof(Stack)); - p_stack->id = getId(); p_stack->s_id = getS_id(STACK, 1); p_stack->length = 0; p_stack->top = NULL; @@ -11,7 +10,6 @@ Stack *initStack(void) { SNode *initSNode(void) { SNode *p_snode = (SNode *)malloc(sizeof(SNode)); - p_snode->id = getId(); p_snode->s_id = getS_id(STACK_NODE, 2); p_snode->if_malloc = 0; p_snode->next = NULL; @@ -45,7 +43,7 @@ int releaseStack(Stack *p_stack) { p_sndoe = p_sndoe->next; releaseSNode(pl_snode); } - p_stack->id = 0; + freeS_id(p_stack->s_id); p_stack->top = NULL; p_stack->length = 0; free(p_stack); @@ -53,7 +51,7 @@ int releaseStack(Stack *p_stack) { } int releaseSNode(SNode *p_snode) { - p_snode->id = 0; + freeS_id(p_snode->s_id); free(p_snode->value); p_snode->if_malloc = 0; p_snode->value = NULL; diff --git a/stack/stack.h b/stack/stack.h index 9581f5b..7990edf 100644 --- a/stack/stack.h +++ b/stack/stack.h @@ -5,7 +5,6 @@ #include "../list/list_expand.h" typedef struct stack_node{ - unsigned long long id; SID *s_id; _Bool if_malloc; _Bool if_sid; @@ -15,7 +14,6 @@ typedef struct stack_node{ } SNode; typedef struct stack{ - unsigned long long id; SID *s_id; unsigned long long length; SNode *top; diff --git a/tree/tree.c b/tree/tree.c index 519df76..e9b4c87 100644 --- a/tree/tree.c +++ b/tree/tree.c @@ -30,8 +30,7 @@ int safeModeForTree(int ifon) { TNode *initTNode(void) { Node *s_node; - TNode *p_tnode = (TNode *)malloc(sizeof(TNode)); - p_tnode->id = getId(); + TNode *p_tnode = (TNode *)malloc(sizeof(TNode)); p_tnode->s_id = getS_id(TREE_NODE, 2); p_tnode->child_num = 0; p_tnode->father = NULL; @@ -60,8 +59,7 @@ TNode *initTNode(void) { Tree *initTree(void) { Node *s_node; - Tree *p_tree = (Tree *)malloc(sizeof(Tree)); - p_tree->id = getId(); + Tree *p_tree = (Tree *)malloc(sizeof(Tree)); p_tree->s_id = getS_id(TREE, 1); p_tree->root = NULL; if (if_safeModeForTree) { @@ -270,7 +268,7 @@ unsigned long long getIndexByChild(TNode *f_tnode, TNode *c_tnode) { int m_index = 0; while (p_node != NULL) { TNode *p_tnode = (TNode *)p_node->value; - if (p_tnode->id == c_tnode->id) { + if (p_tnode->s_id == c_tnode->s_id) { return m_index; } m_index++; @@ -387,7 +385,7 @@ int releaseTNode(TNode *p_tnode) { } p_tnode->value = NULL; p_tnode->type = VOID; - p_tnode->id = 0; + freeS_id(p_tnode->s_id); p_tnode->if_malloc = 0; free(p_tnode); } @@ -397,7 +395,7 @@ int releaseTNode(TNode *p_tnode) { int releaseTree(Tree *p_tree) { TreeThroughUp(p_tree, _doreleaseTree); p_tree->root = NULL; - p_tree->id = 0; + freeS_id(p_tree->s_id); free(p_tree); return 0; } @@ -408,7 +406,7 @@ int _doreleaseTree(TNode *p_tnode, unsigned long long height) { } int releaseOnlyTree(Tree *p_tree) { - p_tree->id = 0; + freeS_id(p_tree->s_id); p_tree->root = NULL; free(p_tree); return 0; @@ -428,7 +426,7 @@ int releaseOnlyTNode(TNode *p_tnode) { } p_tnode->value = NULL; p_tnode->type = VOID; - p_tnode->id = 0; + freeS_id(p_tnode->s_id); p_tnode->if_malloc = 0; free(p_tnode); return 0; diff --git a/tree/tree.h b/tree/tree.h index 75afa5d..f230b57 100644 --- a/tree/tree.h +++ b/tree/tree.h @@ -5,8 +5,7 @@ #include "../list/list_expand.h" typedef struct tree_node -{ - unsigned long long id; +{ SID *s_id; List *home; struct tree_node *father; @@ -19,8 +18,7 @@ typedef struct tree_node }TNode; typedef struct tree -{ - unsigned long long id; +{ SID *s_id; _Bool if_sid; TNode *root; From 56f677a22ba8e5c4f8072df1f18cf4984a0b36df Mon Sep 17 00:00:00 2001 From: Saturneic Date: Mon, 30 Jul 2018 18:18:58 +0800 Subject: [PATCH 31/31] Fixed --- list/list.c | 12 ++++++------ list/list_expand.c | 8 ++++---- tree/tree_expand.c | 12 ++++++------ 3 files changed, 16 insertions(+), 16 deletions(-) diff --git a/list/list.c b/list/list.c index 7d2a6d4..2734d38 100644 --- a/list/list.c +++ b/list/list.c @@ -33,7 +33,7 @@ int releaseSingleListForsafeModeForNode(List *p_list) { List *plv_node = NULL; while (p_node != NULL) { plv_node = (List *)p_node->value; - plv_node->id = 0; + freeS_id(plv_node->s_id); plv_node->head = NULL; plv_node->length = 0; plv_node->tail = NULL; @@ -43,7 +43,7 @@ int releaseSingleListForsafeModeForNode(List *p_list) { p_list->head = NULL; p_list->length = 0; p_list->tail = NULL; - p_list->id = 0; + freeS_id(p_list->s_id); free(p_list); return 0; } @@ -53,7 +53,7 @@ int releaseSingleNodeForsafeModeForNode(List *p_list) { Node *pnv_node = NULL; while (p_node != NULL) { pnv_node = (Node *)p_node->value; - pnv_node->id = 0; + freeS_id(pnv_node->s_id); pnv_node->if_malloc = 0; pnv_node->last = NULL; pnv_node->next = NULL; @@ -62,7 +62,7 @@ int releaseSingleNodeForsafeModeForNode(List *p_list) { free(pnv_node); p_node = p_node->next; } - p_list->id = 0; + free(p_list->s_id); p_list->head = NULL; p_list->length = 0; p_list->tail = NULL; @@ -194,7 +194,7 @@ int releaseList(List *p_list) { p_list->head = NULL; p_list->tail = NULL; p_list->length = 0; - freeS_id(p_list->s_id) + freeS_id(p_list->s_id); free(p_list); return 0; } @@ -437,7 +437,7 @@ List *copyList(List *p_list) { List *t_list = initList(); t_list->head = p_list->head; t_list->tail = p_list->tail; - t_list->id = p_list->id; + t_list->s_id = p_list->s_id; p_node = p_list->head; while (p_node != NULL) { t_node = copyNode(p_node); diff --git a/list/list_expand.c b/list/list_expand.c index d4b647a..84b8157 100644 --- a/list/list_expand.c +++ b/list/list_expand.c @@ -93,7 +93,7 @@ void printListInfo(List *p_list, int priority) { int i = 0; Node *p_node; for (i = 0; i < priority; i++) printf(" "); - printf("###LIST(location:%p, id:%llu){\n", p_list, p_list->id); + printf("###LIST(location:%p, id:%s){\n", p_list, s_idToASCIIString(p_list->s_id)); for (i = 0; i < priority + 1; i++) printf(" "); printf("HEAD->%p / Tail->%p / Length:%llu\n", p_list->head, p_list->tail, p_list->length); p_node = p_list->head; @@ -141,7 +141,7 @@ void printList(List *p_list) { void printNodeInfo(Node *p_node, int priority) { int i; for (i = 0; i < priority; i++) printf(" "); - printf("#NODE(location:%p, id:%llu){\n", p_node, p_node->id); + printf("#NODE(location:%p, id:%s){\n", p_node, s_idToASCIIString(p_node->s_id)); for (i = 0; i < priority + 1; i++) printf(" "); printf("NEXT->%p / LAST->%p / MALLOC:%d\n", p_node->next, p_node->last, p_node->if_malloc); if (p_node->type == INT) { @@ -171,7 +171,7 @@ void printNodeInfo(Node *p_node, int priority) { void printNode(Node *p_node) { int i; - printf("#NODE(location:%p, id:%llu){\n", p_node, p_node->id); + printf("#NODE(location:%p, id:%s){\n", p_node, s_idToASCIIString(p_node->s_id)); printf(" "); printf("NEXT->%p / LAST->%p\n", p_node->next, p_node->last); for (i = 0; i < 1; i++) printf(" "); @@ -321,7 +321,7 @@ unsigned long long getIndexByNode(List *p_list, Node *p_node) { Node *t_node = p_list->head; unsigned long long index = 0; while (t_node != NULL) { - if (p_node->id == t_node->id) return index; + if (p_node->s_id == t_node->s_id) return index; index++; t_node = t_node->next; } diff --git a/tree/tree_expand.c b/tree/tree_expand.c index 1f30a1f..48e891a 100644 --- a/tree/tree_expand.c +++ b/tree/tree_expand.c @@ -64,7 +64,7 @@ int printTNode(TNode *p_tnode, int priority) { if (priority == 0) printf("###"); else printf("#"); - printf("TNode(id: %llu)\n", p_tnode->id); + printf("TNode(id: %s)\n", s_idToASCIIString(p_tnode->s_id)); for (i = 0; i < priority + 1; i++) printf(" "); printf("ifMalloc: "); if (p_tnode->if_malloc) { @@ -102,7 +102,7 @@ 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); + printf("TNode(id: %s)\n", s_idToASCIIString(p_tnode->s_id)); for (i = 0; i < priority + 1; i++) printf(" "); printf("ifMalloc: "); if (p_tnode->if_malloc) { @@ -126,7 +126,7 @@ int printTNodeWithHome(TNode *p_tnode,int priority) { if (p_tnode->father != NULL) { for (i = 0; i < priority + 1; i++) printf(" "); - printf("Father id: %llu\n", p_tnode->father->id); + printf("Father id: %s\n", s_idToASCIIString(p_tnode->father->s_id)); } else { @@ -158,7 +158,7 @@ int printTNodeWithFamily(TNode *p_tnode, int priority) { for (i = 0; i < priority; i++) printf(" "); if (priority == 0) printf("###"); else printf("#"); - printf("TNode(id: %llu)\n", p_tnode->id); + printf("TNode(id: %s)\n", s_idToASCIIString(p_tnode->s_id)); for (i = 0; i < priority + 1; i++) printf(" "); printf("ifMalloc: "); if (p_tnode->if_malloc) { @@ -182,7 +182,7 @@ int printTNodeWithFamily(TNode *p_tnode, int priority) { if (p_tnode->father != NULL) { for (i = 0; i < priority + 1; i++) printf(" "); - printf("Father id: %llu\n", p_tnode->father->id); + printf("Father id: %s\n", s_idToASCIIString(p_tnode->father->s_id)); } else { @@ -208,7 +208,7 @@ int printTNodeWithFamily(TNode *p_tnode, int priority) { int printTree(Tree *p_tree) { printf("###"); - printf("Tree(id: %llu)",p_tree->id); + printf("Tree(id: %s)",s_idToASCIIString(p_tree->s_id)); printTNodeWithFamily(p_tree->root,0); return 0; }