↩ revert:

This commit is contained in:
lzy
2024-05-27 02:33:10 +08:00
parent 2336f88407
commit a277dec1fe
136 changed files with 606 additions and 606 deletions

View File

@@ -4,9 +4,9 @@
#include "llist.h"
LLIST* llist_create(int initsize)
LLIST *llist_create(int initsize)
{
LLIST* new;
LLIST *new;
new = malloc(sizeof(*new)); // !!! 不是sizeof(initsize),也不是new,是*new
if (NULL == new)
@@ -19,9 +19,9 @@ LLIST* llist_create(int initsize)
return new;
}
int llist_insert(LLIST* ptr, const void* data, int mode)
int llist_insert(LLIST *ptr, const void *data, int mode)
{
struct llist_node_st* newnode;
struct llist_node_st *newnode;
newnode = malloc(sizeof(*newnode) + ptr->size); // -4
if (NULL == newnode)
@@ -51,9 +51,9 @@ int llist_insert(LLIST* ptr, const void* data, int mode)
return 0;
}
static struct llist_node_st* find_(LLIST* ptr, const void* key, llist_cmp* cmp)
static struct llist_node_st *find_(LLIST *ptr, const void *key, llist_cmp *cmp)
{
struct llist_node_st* cur;
struct llist_node_st *cur;
for (cur = ptr->head.next; cur != &ptr->head; cur = cur->next)
{
@@ -64,9 +64,9 @@ static struct llist_node_st* find_(LLIST* ptr, const void* key, llist_cmp* cmp)
return cur; // 找不到的时候返回的cur就是ptr返回NULL
}
void* llist_find(LLIST* ptr, const void* key, llist_cmp* cmp)
void *llist_find(LLIST *ptr, const void *key, llist_cmp *cmp)
{
struct llist_node_st* node;
struct llist_node_st *node;
node = find_(ptr, key, cmp);
if (node == &ptr->head)
return NULL;
@@ -74,9 +74,9 @@ void* llist_find(LLIST* ptr, const void* key, llist_cmp* cmp)
return node->data;
}
int llist_delete(LLIST* ptr, const void* key, llist_cmp* cmp)
int llist_delete(LLIST *ptr, const void *key, llist_cmp *cmp)
{
struct llist_node_st* node;
struct llist_node_st *node;
node = find_(ptr, key, cmp);
if (node == &ptr->head)
@@ -89,9 +89,9 @@ int llist_delete(LLIST* ptr, const void* key, llist_cmp* cmp)
return 0;
}
int llist_fetch(LLIST* ptr, const void* key, llist_cmp* cmp, void* data)
int llist_fetch(LLIST *ptr, const void *key, llist_cmp *cmp, void *data)
{
struct llist_node_st* node;
struct llist_node_st *node;
node = find_(ptr, key, cmp);
if (node == &ptr->head)
@@ -108,15 +108,15 @@ int llist_fetch(LLIST* ptr, const void* key, llist_cmp* cmp, void* data)
return 0;
}
void llist_travel(LLIST* ptr, llist_op* op)
void llist_travel(LLIST *ptr, llist_op *op)
{
struct llist_node_st* cur;
struct llist_node_st *cur;
for (cur = ptr->head.next; cur != &ptr->head; cur = cur->next)
op(cur->data);
}
void llist_destroy(LLIST* ptr)
void llist_destroy(LLIST *ptr)
{
struct llist_node_st *cur, *next;

View File

@@ -7,8 +7,8 @@
// !!! 变长结构体
struct llist_node_st
{
struct llist_node_st* prev;
struct llist_node_st* next;
struct llist_node_st *prev;
struct llist_node_st *next;
// data要放在最后
char data[1]; // 占位符数据的起始。C99才只是[0]
};
@@ -19,21 +19,21 @@ typedef struct
struct llist_node_st head;
} LLIST;
typedef void llist_op(const void*);
typedef int llist_cmp(const void*, const void*);
typedef void llist_op(const void *);
typedef int llist_cmp(const void *, const void *);
LLIST* llist_create(int initsize);
LLIST *llist_create(int initsize);
int llist_insert(LLIST* ptr, const void* data, int mode);
int llist_insert(LLIST *ptr, const void *data, int mode);
void* llist_find(LLIST* ptr, const void* key, llist_cmp*);
void *llist_find(LLIST *ptr, const void *key, llist_cmp *);
int llist_delete(LLIST*, const void* key, llist_cmp*);
int llist_delete(LLIST *, const void *key, llist_cmp *);
int llist_fetch(LLIST*, const void* key, llist_cmp*, void* data);
int llist_fetch(LLIST *, const void *key, llist_cmp *, void *data);
void llist_travel(LLIST* ptr, llist_op* op);
void llist_travel(LLIST *ptr, llist_op *op);
void llist_destroy(LLIST* ptr);
void llist_destroy(LLIST *ptr);
#endif

View File

@@ -13,16 +13,16 @@ struct score_st
int chinese;
};
static int print_s(void* record)
static int print_s(void *record)
{
struct score_st* r = record;
struct score_st *r = record;
printf("%d %s %d %d\n", r->id, r->name, r->math, r->chinese);
}
int main( )
{
STACK* st;
STACK *st;
struct score_st tmp;
int i, ret;

View File

@@ -2,28 +2,28 @@
#include "stack.h"
LLIST* stack_create(int initsize)
LLIST *stack_create(int initsize)
{
return llist_create(initsize);
}
int stack_push(STACK* ptr, const void* data)
int stack_push(STACK *ptr, const void *data)
{
return llist_insert(ptr, data, LLIST_FORWARD);
}
static int always_match(const void* p1, const void* p2)
static int always_match(const void *p1, const void *p2)
{
return 0;
}
int stack_pop(STACK* ptr, void* data)
int stack_pop(STACK *ptr, void *data)
{
// !!! 假接口
return llist_fetch(ptr, (void*)0, always_match, data);
return llist_fetch(ptr, (void *)0, always_match, data);
}
void stack_destroy(STACK* ptr)
void stack_destroy(STACK *ptr)
{
llist_destroy(ptr);
}

View File

@@ -5,12 +5,12 @@
typedef LLIST STACK;
STACK* stack_create(int);
STACK *stack_create(int);
int stack_push(STACK*, const void* data);
int stack_push(STACK *, const void *data);
int stack_pop(STACK*, void* data);
int stack_pop(STACK *, void *data);
void stack_destroy(STACK*);
void stack_destroy(STACK *);
#endif