From a8525b639bba80332c59f785269f289efb3f7995 Mon Sep 17 00:00:00 2001 From: Saturneic Date: Mon, 11 Jun 2018 15:57:25 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=B7=BB=E5=8A=A0=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 */