修改添加。

This commit is contained in:
Saturneic 2018-06-11 15:57:25 +08:00
parent bda6e3fea7
commit a8525b639b
3 changed files with 97 additions and 23 deletions

View File

@ -16,26 +16,26 @@ int addDoubleForComplex(Node *, double);//为复合节点添加一个特定类
int addStringForComplex(Node *, char *);//为复合节点添加一个特定类型的值 int addStringForComplex(Node *, char *);//为复合节点添加一个特定类型的值
int addPointerForComplex(Node *, void *);//为复合节点添加一个特定类型的值 int addPointerForComplex(Node *, void *);//为复合节点添加一个特定类型的值
Node *findByIndex(List *, unsigned long long);//根据位置查找一个节点 Node *findByIndexForNode(List *, unsigned long long);//根据位置查找一个节点
Node *findByInt(List *, int);//依照特定类型查找一个节点 Node *findByIntForNode(List *, int);//依照特定类型查找一个节点
Node *findByDouble(List *, double);//依照特定类型查找一个节点 Node *findByDoubleForNode(List *, double);//依照特定类型查找一个节点
Node *findByString(List *, char *);//依照特定类型查找一个节点 Node *findByStringForNode(List *, char *);//依照特定类型查找一个节点
Node *findByPointer(List *, void *);//依照特定类型查找一个节点 Node *findByPointerForNode(List *, void *);//依照特定类型查找一个节点
List *m_findByInt(List*, int);//根据位置查找所有匹配的节点 List *m_findByIntForNode(List*, int);//根据位置查找所有匹配的节点
List *m_findByDouble(List*, double);//根据位置查找所有匹配的节点 List *m_findByDoubleForNode(List*, double);//根据位置查找所有匹配的节点
List *m_findByString(List*, char *);//根据位置查找所有匹配的节点 List *m_findByStringForNode(List*, char *);//根据位置查找所有匹配的节点
List *m_findByPointer(List*, void *);//根据位置查找所有匹配的节点 List *m_findByPointerForNode(List*, void *);//根据位置查找所有匹配的节点
void printListInfo(List *p_list,int priority);//打印列表的详细信息 void printListInfo(List *p_list,int priority);//打印列表的详细信息
void printNodeInfo(Node *p_node,int priority);//打印节点的详细信息 void printNodeInfo(Node *p_node,int priority);//打印节点的详细信息
void printList(List *);//打印列表 void printList(List *);//打印列表
void printNode(Node *p_node);//打印节点 void printNode(Node *p_node);//打印节点
int getByInt(Node *);//直接得到节点的值 int getByIntForNode(Node *);//直接得到节点的值
double getByDouble(Node *);//直接得到节点的值 double getByDoubleForNode(Node *);//直接得到节点的值
char *getByString(Node *);//直接得到节点的值 char *getByStringForNode(Node *);//直接得到节点的值
void *getByPointer(Node *);//直接得到节点的值 void *getByPointerForNode(Node *);//直接得到节点的值
int listThrough(List *p_list, int (*p_func)(void *, const char *));//遍历链表并不断调用目标函数。目标函数将接受节点储存值的指针及其类型。 int listThrough(List *p_list, int (*p_func)(void *, const char *));//遍历链表并不断调用目标函数。目标函数将接受节点储存值的指针及其类型。
@ -77,7 +77,7 @@ Node *nodeWithComplex(void){
return p_node; 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; Node *p_node = p_list->head;
for(unsigned long long i= 0; i < m_index; i++){ for(unsigned long long i= 0; i < m_index; i++){
p_node = p_node->next; p_node = p_node->next;
@ -104,22 +104,22 @@ int listThrough(List *p_list, int (*p_func)(void *, const char *)){
return 0; return 0;
} }
int getByInt(Node *p_node){ int getByIntForNode(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; else return -1;
} }
char *getByString(Node *p_node){ char *getByStringForNode(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; else return NULL;
} }
double getByDouble(Node *p_node){ double getByDoubleForNode(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; else return -1;
} }
void *getByPointer(Node *p_node){ void *getByPointerForNode(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; else return NULL;
} }
@ -225,7 +225,7 @@ void printList(List *p_list){
printf("]"); printf("]");
} }
Node *findByInt(List *p_list, int target){ Node *findByIntForNode(List *p_list, int target){
int *p_target = (int *)malloc(sizeof(int)); int *p_target = (int *)malloc(sizeof(int));
*p_target = target; *p_target = target;
Node *t_node = findByValue(p_list, "int", p_target); Node *t_node = findByValue(p_list, "int", p_target);
@ -233,7 +233,7 @@ Node *findByInt(List *p_list, int target){
return t_node; return t_node;
} }
Node *findByDouble(List *p_list, double target){ Node *findByDoubleForNode(List *p_list, double target){
double *p_target = (double *)malloc(sizeof(double)); double *p_target = (double *)malloc(sizeof(double));
*p_target = target; *p_target = target;
Node *t_node = findByValue(p_list, "double", p_target); Node *t_node = findByValue(p_list, "double", p_target);
@ -241,7 +241,7 @@ Node *findByDouble(List *p_list, double target){
return t_node; 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)); char *p_temp = (char *)malloc(sizeof(char)*(strlen(target)+1));
strcpy(p_temp, target); strcpy(p_temp, target);
Node *t_node = findByValue(p_list, "string", p_temp); Node *t_node = findByValue(p_list, "string", p_temp);
@ -249,7 +249,7 @@ Node *findByString(List *p_list, char *target){
return t_node; 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); Node *t_node = findByValue(p_list, "pointer", target);
return t_node; return t_node;
} }

View File

@ -6,7 +6,7 @@
// Copyright © 2018年 ZE. All rights reserved. // Copyright © 2018年 ZE. All rights reserved.
// //
#include "stack.h" #include "stack_expand.h"
int main(int argc, char **argv){ int main(int argc, char **argv){

74
stack/stack_expand.h Normal file
View File

@ -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 */