添加并修改了一些函数,开始写栈。
This commit is contained in:
parent
d3550aa26b
commit
510b191de5
16
list/list.c
16
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;
|
||||
}
|
||||
|
60
list/list.h
60
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
|
||||
|
@ -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
|
||||
|
14
stack/stack.c
Normal file
14
stack/stack.c
Normal file
@ -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;
|
||||
}
|
37
stack/stack.h
Normal file
37
stack/stack.h
Normal file
@ -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 */
|
Loading…
Reference in New Issue
Block a user