↩ 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

@@ -16,7 +16,7 @@
#define NR_BALL 27
int check(queue* qu)
int check(queue *qu)
{
int i = (qu->head + 1) % MAXSIZE;
@@ -33,7 +33,7 @@ int check(queue* qu)
int main( )
{
int i;
queue* qu;
queue *qu;
int t, value;
int time;
sqstack *st_min, *st_fivemin, *st_hour;

View File

@@ -4,9 +4,9 @@
#include "queue.h"
queue* qu_create( )
queue *qu_create( )
{
queue* sq;
queue *sq;
sq = malloc(sizeof(*sq));
if (NULL == sq)
@@ -18,12 +18,12 @@ queue* qu_create( )
return sq;
}
int qu_isempty(queue* sq)
int qu_isempty(queue *sq)
{
return (sq->head == sq->tail);
}
int qu_enqueue(queue* sq, datatype* x)
int qu_enqueue(queue *sq, datatype *x)
{
if ((sq->tail + 1) % MAXSIZE == sq->head)
return -1;
@@ -34,7 +34,7 @@ int qu_enqueue(queue* sq, datatype* x)
return 0;
}
int qu_dequeue(queue* sq, datatype* x)
int qu_dequeue(queue *sq, datatype *x)
{
if (qu_isempty(sq))
return -1;
@@ -45,7 +45,7 @@ int qu_dequeue(queue* sq, datatype* x)
return 0;
}
void qu_travel(queue* sq)
void qu_travel(queue *sq)
{
if (sq->head == sq->tail)
return;
@@ -61,12 +61,12 @@ void qu_travel(queue* sq)
printf("%d \n", sq->data[i]);
}
void qu_clear(queue* sq)
void qu_clear(queue *sq)
{
sq->head = sq->tail;
}
void qu_destroy(queue* sq)
void qu_destroy(queue *sq)
{
free(sq);
}

View File

@@ -12,18 +12,18 @@ typedef struct
} queue;
queue* qu_create( );
queue *qu_create( );
int qu_isempty( );
int qu_enqueue(queue*, datatype*);
int qu_enqueue(queue *, datatype *);
int qu_dequeue(queue*, datatype*);
int qu_dequeue(queue *, datatype *);
void qu_travel(queue*);
void qu_travel(queue *);
void qu_clear(queue*);
void qu_clear(queue *);
void qu_destroy(queue*);
void qu_destroy(queue *);
#endif

View File

@@ -3,9 +3,9 @@
#include "sqstack.h"
sqstack* st_create(void)
sqstack *st_create(void)
{
sqstack* st;
sqstack *st;
st = malloc(sizeof(*st));
if (NULL == st)
@@ -16,12 +16,12 @@ sqstack* st_create(void)
return st;
}
int st_isempty(sqstack* st)
int st_isempty(sqstack *st)
{
return (-1 == st->top);
}
int st_push(sqstack* st, type* data)
int st_push(sqstack *st, type *data)
{
if (SIZE - 1 == st->top)
return -1;
@@ -32,7 +32,7 @@ int st_push(sqstack* st, type* data)
}
/* 取出栈顶元素 */
int st_pop(sqstack* st, type* data)
int st_pop(sqstack *st, type *data)
{
if (st_isempty(st))
return -1;
@@ -44,7 +44,7 @@ int st_pop(sqstack* st, type* data)
/* 查看栈顶元素 */
int st_top(sqstack* st, type* data)
int st_top(sqstack *st, type *data)
{
if (st_isempty(st))
return -1;
@@ -54,7 +54,7 @@ int st_top(sqstack* st, type* data)
return 0;
}
void st_travel(sqstack* st)
void st_travel(sqstack *st)
{
if (st_isempty(st))
return;
@@ -66,7 +66,7 @@ void st_travel(sqstack* st)
printf("\n");
}
void st_destroy(sqstack* st)
void st_destroy(sqstack *st)
{
free(st);
}

View File

@@ -11,20 +11,20 @@ typedef struct node_st
int top;
} sqstack;
sqstack* st_create(void);
sqstack *st_create(void);
int st_isempty(sqstack*);
int st_isempty(sqstack *);
int st_push(sqstack*, type*);
int st_push(sqstack *, type *);
/* 取出栈顶元素 */
int st_pop(sqstack*, type*);
int st_pop(sqstack *, type *);
/* 查看栈顶元素 */
int st_top(sqstack*, type*);
int st_top(sqstack *, type *);
void st_travel(sqstack*);
void st_travel(sqstack *);
void st_destroy(sqstack*);
void st_destroy(sqstack *);
#endif

View File

@@ -6,7 +6,7 @@
// !!! 课程不完整,程序未写完
// TODO: snum和sop需要不同的datatype
static void compute(sqstack* snum, int* op)
static void compute(sqstack *snum, int *op)
{
datatype n1, n2, n;
@@ -25,7 +25,7 @@ static void compute(sqstack* snum, int* op)
st_push(snum, &n);
}
static deal_bracket(sqstack* snum, sqstack* sop)
static deal_bracket(sqstack *snum, sqstack *sop)
{
datatype old_op;
@@ -54,7 +54,7 @@ static int get_pri(int op)
}
static void deal_op(sqstack* snum, sqstack* sop, char op)
static void deal_op(sqstack *snum, sqstack *sop, char op)
{
datatype old_op;

View File

@@ -3,9 +3,9 @@
#include "sqstack.h"
sqstack* st_create(void)
sqstack *st_create(void)
{
sqstack* st;
sqstack *st;
st = malloc(sizeof(*st));
if (NULL == st)
@@ -16,12 +16,12 @@ sqstack* st_create(void)
return st;
}
int st_isempty(sqstack* st)
int st_isempty(sqstack *st)
{
return (-1 == st->top);
}
int st_push(sqstack* st, datatype* data)
int st_push(sqstack *st, datatype *data)
{
if (MAXSIZE - 1 == st->top)
return -1;
@@ -32,7 +32,7 @@ int st_push(sqstack* st, datatype* data)
}
/* 取出栈顶元素 */
int st_pop(sqstack* st, datatype* data)
int st_pop(sqstack *st, datatype *data)
{
if (st_isempty(st))
return -1;
@@ -44,7 +44,7 @@ int st_pop(sqstack* st, datatype* data)
/* 查看栈顶元素 */
int st_top(sqstack* st, datatype* data)
int st_top(sqstack *st, datatype *data)
{
if (st_isempty(st))
return -1;
@@ -54,7 +54,7 @@ int st_top(sqstack* st, datatype* data)
return 0;
}
void st_travel(sqstack* st)
void st_travel(sqstack *st)
{
if (st_isempty(st))
return;
@@ -66,7 +66,7 @@ void st_travel(sqstack* st)
printf("\n");
}
void st_destroy(sqstack* st)
void st_destroy(sqstack *st)
{
free(st);
}

View File

@@ -11,20 +11,20 @@ typedef struct node_st
int top;
} sqstack;
sqstack* st_create(void);
sqstack *st_create(void);
int st_isempty(sqstack*);
int st_isempty(sqstack *);
int st_push(sqstack*, datatype*);
int st_push(sqstack *, datatype *);
/* 取出栈顶元素 */
int st_pop(sqstack*, datatype*);
int st_pop(sqstack *, datatype *);
/* 查看栈顶元素 */
int st_top(sqstack*, datatype*);
int st_top(sqstack *, datatype *);
void st_travel(sqstack*);
void st_travel(sqstack *);
void st_destroy(sqstack*);
void st_destroy(sqstack *);
#endif

View File

@@ -5,8 +5,8 @@
int main( )
{
sqlist* list = NULL;
sqlist* list1 = NULL;
sqlist *list = NULL;
sqlist *list1 = NULL;
datatype arr[] = {12, 23, 34, 45, 56};
datatype arr1[] = {89, 90, 78, 67, 56, 43};

View File

@@ -3,9 +3,9 @@
#include "sqlist.h"
sqlist* sqlist_create( )
sqlist *sqlist_create( )
{
sqlist* me;
sqlist *me;
me = malloc(sizeof(*me));
if (NULL == me)
@@ -16,7 +16,7 @@ sqlist* sqlist_create( )
return me;
}
void sqlist_create1(sqlist** ptr)
void sqlist_create1(sqlist **ptr)
{
*ptr = malloc(sizeof(**ptr));
if (NULL == *ptr)
@@ -26,7 +26,7 @@ void sqlist_create1(sqlist** ptr)
return;
}
int sqlist_insert(sqlist* me, int i, datatype* data)
int sqlist_insert(sqlist *me, int i, datatype *data)
{
int j;
@@ -48,7 +48,7 @@ int sqlist_insert(sqlist* me, int i, datatype* data)
return 0;
}
int sqlist_delete(sqlist* me, int i)
int sqlist_delete(sqlist *me, int i)
{
int j;
@@ -65,7 +65,7 @@ int sqlist_delete(sqlist* me, int i)
return 0;
}
int sqlist_find(sqlist* me, datatype* data)
int sqlist_find(sqlist *me, datatype *data)
{
if (0 == sqlist_isempty(me))
return -1;
@@ -79,25 +79,25 @@ int sqlist_find(sqlist* me, datatype* data)
return -2;
}
int sqlist_isempty(sqlist* me)
int sqlist_isempty(sqlist *me)
{
if (-1 == me->last)
return 0;
return -1;
}
int sqlist_setempty(sqlist* me)
int sqlist_setempty(sqlist *me)
{
me->last = -1;
return 0;
}
int sqlist_getnum(sqlist* me)
int sqlist_getnum(sqlist *me)
{
return me->last + 1;
}
void sqlist_display(sqlist* me)
void sqlist_display(sqlist *me)
{
if (-1 == me->last)
return;
@@ -108,13 +108,13 @@ void sqlist_display(sqlist* me)
printf("\n");
}
int sqlist_destroy(sqlist* me)
int sqlist_destroy(sqlist *me)
{
free(me);
return 0;
}
int sqlist_union(sqlist* list1, sqlist* list2)
int sqlist_union(sqlist *list1, sqlist *list2)
{
// list1 -> 12 23 34 45 56
// list2 -> 78 89 56 23 10

View File

@@ -11,26 +11,26 @@ typedef struct node_st
int last;
} sqlist;
sqlist* sqlist_create( );
void sqlist_create1(sqlist** me);
sqlist *sqlist_create( );
void sqlist_create1(sqlist **me);
int sqlist_insert(sqlist*, int i, datatype* data);
int sqlist_insert(sqlist *, int i, datatype *data);
int sqlist_delete(sqlist*, int i);
int sqlist_delete(sqlist *, int i);
int sqlist_find(sqlist*, datatype* data);
int sqlist_find(sqlist *, datatype *data);
int sqlist_isempty(sqlist*);
int sqlist_isempty(sqlist *);
int sqlist_setempty(sqlist*);
int sqlist_setempty(sqlist *);
int sqlist_getnum(sqlist*);
int sqlist_getnum(sqlist *);
void sqlist_display(sqlist*);
void sqlist_display(sqlist *);
int sqlist_destroy(sqlist*);
int sqlist_destroy(sqlist *);
int sqlist_union(sqlist*, sqlist*);
int sqlist_union(sqlist *, sqlist *);
#endif

View File

@@ -3,8 +3,8 @@
struct list_head
{
struct list_head* prev;
struct list_head* next;
struct list_head *prev;
struct list_head *next;
};
#define LIST_HEAD_INIT(name) \
@@ -14,9 +14,9 @@ struct list_head
#define LIST_HEAD(name) struct list_head name = LIST_HEAD_INIT(name)
static inline void __list_add(struct list_head* new,
struct list_head* prev,
struct list_head* next)
static inline void __list_add(struct list_head *new,
struct list_head *prev,
struct list_head *next)
{
next->prev = new;
new->next = next;
@@ -24,7 +24,7 @@ static inline void __list_add(struct list_head* new,
prev->next = new;
}
static inline void list_add(struct list_head* new, struct list_head* head)
static inline void list_add(struct list_head *new, struct list_head *head)
{
__list_add(new, head, head->next);
}
@@ -43,12 +43,12 @@ static inline void list_add(struct list_head* new, struct list_head* head)
*
*/
#define offsetof(TYPE, MEMBER) ((size_t) & ((TYPE*)0)->MEMBER)
#define offsetof(TYPE, MEMBER) ((size_t) & ((TYPE *)0)->MEMBER)
#define container_of(ptr, type, member) \
({ \
const typeof(((type*)0)->member)* __mptr = (ptr); \
(type*)((char*)__mptr - offsetof(type, member)); \
#define container_of(ptr, type, member) \
({ \
const typeof(((type *)0)->member) *__mptr = (ptr); \
(type *)((char *)__mptr - offsetof(type, member)); \
})
#define list_entry(ptr, type, member) container_of(ptr, type, member)

View File

@@ -14,7 +14,7 @@ struct score_st
int chinese;
};
static void print_s(struct score_st* d)
static void print_s(struct score_st *d)
{
printf("%d %s %d %d \n", d->id, d->name, d->math, d->chinese);
}
@@ -22,8 +22,8 @@ static void print_s(struct score_st* d)
int main( )
{
int i;
struct score_st* datap;
struct list_head* cur;
struct score_st *datap;
struct list_head *cur;
LIST_HEAD(head);

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)
@@ -20,9 +20,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));
if (NULL == newnode)
@@ -56,9 +56,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)
{
@@ -69,14 +69,14 @@ 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)
{
return find_(ptr, key, cmp)->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)
@@ -91,9 +91,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)
@@ -111,15 +111,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

@@ -6,9 +6,9 @@
struct llist_node_st
{
void* data;
struct llist_node_st* prev;
struct llist_node_st* next;
void *data;
struct llist_node_st *prev;
struct llist_node_st *next;
};
typedef struct
@@ -17,21 +17,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

@@ -14,25 +14,25 @@ struct score_st
int chinese;
};
void print_s(const void* record)
void print_s(const void *record)
{
const struct score_st* r = record;
const struct score_st *r = record;
printf("%d %s %d %d\n", r->id, r->name, r->math, r->chinese);
}
int id_cmp(const void* key, const void* record)
int id_cmp(const void *key, const void *record)
{
const int* k = key;
const struct score_st* r = record;
const int *k = key;
const struct score_st *r = record;
return (*k - r->id);
}
int name_cmp(const void* key, const void* record)
int name_cmp(const void *key, const void *record)
{
const char* k = key;
const struct score_st* r = record;
const char *k = key;
const struct score_st *r = record;
return strcmp(k, r->name);
}
@@ -40,7 +40,7 @@ int name_cmp(const void* key, const void* record)
int main( )
{
LLIST* handler;
LLIST *handler;
int i, ret;
struct score_st tmp;
@@ -65,7 +65,7 @@ int main( )
printf("\n\n");
// int id = 3;
char* del_name = "std6";
char *del_name = "std6";
// ret = llist_delete(handler, &id, id_cmp);
ret = llist_delete(handler, del_name, name_cmp);

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

@@ -14,25 +14,25 @@ struct score_st
int chinese;
};
void print_s(const void* record)
void print_s(const void *record)
{
const struct score_st* r = record;
const struct score_st *r = record;
printf("%d %s %d %d\n", r->id, r->name, r->math, r->chinese);
}
int id_cmp(const void* key, const void* record)
int id_cmp(const void *key, const void *record)
{
const int* k = key;
const struct score_st* r = record;
const int *k = key;
const struct score_st *r = record;
return (*k - r->id);
}
int name_cmp(const void* key, const void* record)
int name_cmp(const void *key, const void *record)
{
const char* k = key;
const struct score_st* r = record;
const char *k = key;
const struct score_st *r = record;
return strcmp(k, r->name);
}
@@ -40,7 +40,7 @@ int name_cmp(const void* key, const void* record)
int main( )
{
LLIST* handler;
LLIST *handler;
int i, ret;
struct score_st tmp;
@@ -65,7 +65,7 @@ int main( )
printf("\n\n");
// int id = 3;
char* del_name = "std6";
char *del_name = "std6";
// ret = llist_delete(handler, &id, id_cmp);
ret = llist_delete(handler, del_name, name_cmp);

View File

@@ -4,15 +4,15 @@
#include "llist.h"
int llist_insert(LLIST* ptr, const void* data, int mode);
void* llist_find(LLIST* ptr, 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);
void llist_travel(LLIST* ptr, llist_op* op);
int llist_insert(LLIST *ptr, const void *data, int mode);
void *llist_find(LLIST *ptr, 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);
void llist_travel(LLIST *ptr, llist_op *op);
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)
@@ -31,9 +31,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)
@@ -63,9 +63,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)
{
@@ -76,9 +76,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;
@@ -86,9 +86,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)
@@ -101,9 +101,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)
@@ -120,15 +120,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

@@ -4,14 +4,14 @@
#define LLIST_FORWARD 1
#define LLIST_BACKWARD 2
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 *);
// !!! 变长结构体
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]
};
@@ -21,18 +21,18 @@ typedef struct llist_head
int size;
struct llist_node_st head;
int (*insert)(struct llist_head*, const void*, int);
void* (*find)(struct llist_head*, const void*, llist_cmp*);
int (*delete)(struct llist_head*, const void*, llist_cmp*);
int (*fetch)(struct llist_head*, const void*, llist_cmp*, void*);
void (*travel)(struct llist_head*, llist_op*);
int (*insert)(struct llist_head *, const void *, int);
void *(*find)(struct llist_head *, const void *, llist_cmp *);
int (*delete)(struct llist_head *, const void *, llist_cmp *);
int (*fetch)(struct llist_head *, const void *, llist_cmp *, void *);
void (*travel)(struct llist_head *, llist_op *);
} LLIST;
LLIST* llist_create(int initsize);
LLIST *llist_create(int initsize);
void llist_destroy(LLIST* ptr);
void llist_destroy(LLIST *ptr);
#endif

View File

@@ -14,25 +14,25 @@ struct score_st
int chinese;
};
void print_s(const void* record)
void print_s(const void *record)
{
const struct score_st* r = record;
const struct score_st *r = record;
printf("%d %s %d %d\n", r->id, r->name, r->math, r->chinese);
}
int id_cmp(const void* key, const void* record)
int id_cmp(const void *key, const void *record)
{
const int* k = key;
const struct score_st* r = record;
const int *k = key;
const struct score_st *r = record;
return (*k - r->id);
}
int name_cmp(const void* key, const void* record)
int name_cmp(const void *key, const void *record)
{
const char* k = key;
const struct score_st* r = record;
const char *k = key;
const struct score_st *r = record;
return strcmp(k, r->name);
}
@@ -40,7 +40,7 @@ int name_cmp(const void* key, const void* record)
int main( )
{
LLIST* handler;
LLIST *handler;
int i, ret;
struct score_st tmp;

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,9 +19,9 @@ struct llist_head_st
struct llist_node_st head;
};
LLIST* llist_create(int initsize)
LLIST *llist_create(int initsize)
{
struct llist_head_st* new;
struct llist_head_st *new;
new = malloc(sizeof(*new)); // !!! 不是sizeof(initsize),也不是new,是*new
if (NULL == new)
@@ -34,10 +34,10 @@ LLIST* llist_create(int initsize)
return new;
}
int llist_insert(LLIST* p, const void* data, int mode)
int llist_insert(LLIST *p, const void *data, int mode)
{
struct llist_node_st* newnode;
struct llist_head_st* ptr = p;
struct llist_node_st *newnode;
struct llist_head_st *ptr = p;
newnode = malloc(sizeof(*newnode) + ptr->size); // -4
if (NULL == newnode)
@@ -67,11 +67,11 @@ int llist_insert(LLIST* p, const void* data, int mode)
return 0;
}
static struct llist_node_st* find_(struct llist_head_st* ptr,
const void* key,
llist_cmp* cmp)
static struct llist_node_st *find_(struct llist_head_st *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)
{
@@ -82,10 +82,10 @@ static struct llist_node_st* find_(struct llist_head_st* ptr,
return cur; // 找不到的时候返回的cur就是ptr返回NULL
}
void* llist_find(LLIST* p, const void* key, llist_cmp* cmp)
void *llist_find(LLIST *p, const void *key, llist_cmp *cmp)
{
struct llist_head_st* ptr = p;
struct llist_node_st* node;
struct llist_head_st *ptr = p;
struct llist_node_st *node;
node = find_(ptr, key, cmp);
if (node == &ptr->head)
return NULL;
@@ -93,10 +93,10 @@ void* llist_find(LLIST* p, const void* key, llist_cmp* cmp)
return node->data;
}
int llist_delete(LLIST* p, const void* key, llist_cmp* cmp)
int llist_delete(LLIST *p, const void *key, llist_cmp *cmp)
{
struct llist_head_st* ptr = p;
struct llist_node_st* node;
struct llist_head_st *ptr = p;
struct llist_node_st *node;
node = find_(ptr, key, cmp);
if (node == &ptr->head)
@@ -109,10 +109,10 @@ int llist_delete(LLIST* p, const void* key, llist_cmp* cmp)
return 0;
}
int llist_fetch(LLIST* p, const void* key, llist_cmp* cmp, void* data)
int llist_fetch(LLIST *p, const void *key, llist_cmp *cmp, void *data)
{
struct llist_head_st* ptr = p;
struct llist_node_st* node;
struct llist_head_st *ptr = p;
struct llist_node_st *node;
node = find_(ptr, key, cmp);
if (node == &ptr->head)
@@ -129,18 +129,18 @@ int llist_fetch(LLIST* p, const void* key, llist_cmp* cmp, void* data)
return 0;
}
void llist_travel(LLIST* p, llist_op* op)
void llist_travel(LLIST *p, llist_op *op)
{
struct llist_head_st* ptr = p;
struct llist_node_st* cur;
struct llist_head_st *ptr = p;
struct llist_node_st *cur;
for (cur = ptr->head.next; cur != &ptr->head; cur = cur->next)
op(cur->data);
}
void llist_destroy(LLIST* p)
void llist_destroy(LLIST *p)
{
struct llist_head_st* ptr = p;
struct llist_head_st *ptr = p;
struct llist_node_st *cur, *next;
for (cur = ptr->head.next; cur != &ptr->head; cur = next)

View File

@@ -7,21 +7,21 @@
// !!! 实现了隐藏 LLIST 的实现方法
typedef void 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*, const void* data, int mode);
int llist_insert(LLIST *, const void *data, int mode);
void* llist_find(LLIST*, const void* key, llist_cmp*);
void *llist_find(LLIST *, 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*, llist_op*);
void llist_travel(LLIST *, llist_op *);
void llist_destroy(LLIST*);
void llist_destroy(LLIST *);
#endif

View File

@@ -14,25 +14,25 @@ struct score_st
int chinese;
};
void print_s(const void* record)
void print_s(const void *record)
{
const struct score_st* r = record;
const struct score_st *r = record;
printf("%d %s %d %d\n", r->id, r->name, r->math, r->chinese);
}
int id_cmp(const void* key, const void* record)
int id_cmp(const void *key, const void *record)
{
const int* k = key;
const struct score_st* r = record;
const int *k = key;
const struct score_st *r = record;
return (*k - r->id);
}
int name_cmp(const void* key, const void* record)
int name_cmp(const void *key, const void *record)
{
const char* k = key;
const struct score_st* r = record;
const char *k = key;
const struct score_st *r = record;
return strcmp(k, r->name);
}
@@ -40,7 +40,7 @@ int name_cmp(const void* key, const void* record)
int main( )
{
LLIST* handler;
LLIST *handler;
int i, ret;
struct score_st tmp;
@@ -65,7 +65,7 @@ int main( )
printf("\n\n");
// int id = 3;
char* del_name = "std6";
char *del_name = "std6";
// ret = llist_delete(handler, &id, id_cmp);
ret = llist_delete(handler, del_name, name_cmp);

View File

@@ -3,9 +3,9 @@
#include "list.h"
list* list_create( )
list *list_create( )
{
list* me;
list *me;
me = malloc(sizeof(*me));
if (NULL == me)
return NULL;
@@ -16,7 +16,7 @@ list* list_create( )
}
// 从第一个有效节点作为第0个
int list_insert_at(list* me, int i, datatype* data)
int list_insert_at(list *me, int i, datatype *data)
{
int k = 0;
list *node = me, *newnode;
@@ -50,7 +50,7 @@ int list_insert_at(list* me, int i, datatype* data)
}
// 有序插入
int list_order_insert(list* me, datatype* data)
int list_order_insert(list *me, datatype *data)
{
list *p = me, *q;
@@ -68,7 +68,7 @@ int list_order_insert(list* me, datatype* data)
return 0;
}
int list_delete_at(list* me, int i, datatype* data)
int list_delete_at(list *me, int i, datatype *data)
{
int k = 0;
list *p = me, *q;
@@ -98,7 +98,7 @@ int list_delete_at(list* me, int i, datatype* data)
return -2;
}
int list_delete(list* me, datatype* data)
int list_delete(list *me, datatype *data)
{
list *p = me, *q;
while (p->next && p->next->data != *data)
@@ -117,16 +117,16 @@ int list_delete(list* me, datatype* data)
return 0;
}
int list_isempty(list* me)
int list_isempty(list *me)
{
if (NULL == me->next)
return 0;
return 1;
}
void list_display(list* me)
void list_display(list *me)
{
list* node = me->next;
list *node = me->next;
if (0 == list_isempty(me))
return;
@@ -140,7 +140,7 @@ void list_display(list* me)
return;
}
void list_destroy(list* me)
void list_destroy(list *me)
{
list *node, *next;

View File

@@ -6,21 +6,21 @@ typedef int datatype;
typedef struct node_st
{
datatype data;
struct node_st* next;
struct node_st *next;
} list;
list* list_create( );
list *list_create( );
int list_insert_at(list* me, int i, datatype* data);
int list_order_insert(list* me, datatype* data);
int list_insert_at(list *me, int i, datatype *data);
int list_order_insert(list *me, datatype *data);
int list_delete_at(list* me, int i, datatype* data);
int list_delete(list* me, datatype* data);
int list_delete_at(list *me, int i, datatype *data);
int list_delete(list *me, datatype *data);
int list_isempty(list* me);
int list_isempty(list *me);
void list_display(list* me);
void list_destroy(list* me);
void list_display(list *me);
void list_destroy(list *me);
#endif

View File

@@ -5,7 +5,7 @@
int main( )
{
list* l;
list *l;
datatype arr[] = {12, 9, 23, 2, 34, 6, 45};
l = list_create( );

View File

@@ -6,7 +6,7 @@
typedef struct node_st
{
int data;
struct node_st* next;
struct node_st *next;
} list;
// try something
@@ -32,7 +32,7 @@ list *jose_create(int a[], int n)
}
#endif
list* jose_create(int n)
list *jose_create(int n)
{
list *me, *newnode, *cur;
int i = 1;
@@ -61,9 +61,9 @@ list* jose_create(int n)
return me;
}
void jose_show(list* me)
void jose_show(list *me)
{
list* list;
list *list;
for (list = me; list->next != me; list = list->next)
{
@@ -74,7 +74,7 @@ void jose_show(list* me)
printf("%d\n", list->data);
}
void jose_kill(list** me, int n)
void jose_kill(list **me, int n)
{
list *cur = *me, *node;
int i = 1;
@@ -103,7 +103,7 @@ void jose_kill(list** me, int n)
int main( )
{
list* list;
list *list;
list = jose_create(JOSE_NUM);

View File

@@ -6,7 +6,7 @@
int main( )
{
int i, ret;
struct node_st* list = NULL;
struct node_st *list = NULL;
struct score_st tmp;
for (i = 0; i < 7; i++)
@@ -28,7 +28,7 @@ int main( )
printf("\n\n");
int id = 13;
struct score_st* ptr;
struct score_st *ptr;
ptr = list_find(&list, id);
if (NULL == ptr)
printf("Can not find!\n");

View File

@@ -21,9 +21,9 @@ struct node_st *list_insert(struct node_st *list, struct score_st *data)
}
#endif
int list_insert(struct node_st** list, struct score_st* data)
int list_insert(struct node_st **list, struct score_st *data)
{
struct node_st* new;
struct node_st *new;
new = malloc(sizeof(*new));
if (NULL == new)
@@ -36,9 +36,9 @@ int list_insert(struct node_st** list, struct score_st* data)
return 0;
}
void list_show(struct node_st* list)
void list_show(struct node_st *list)
{
struct node_st* cur;
struct node_st *cur;
for (cur = list; NULL != cur; cur = cur->next)
{
@@ -51,9 +51,9 @@ void list_show(struct node_st* list)
}
// 删除首位
int list_delete(struct node_st** list)
int list_delete(struct node_st **list)
{
struct node_st* cur;
struct node_st *cur;
if (NULL == *list)
return -1;
@@ -66,9 +66,9 @@ int list_delete(struct node_st** list)
return 0;
}
struct score_st* list_find(struct node_st** list, int id)
struct score_st *list_find(struct node_st **list, int id)
{
struct node_st* cur;
struct node_st *cur;
if (NULL == *list)
return NULL;
@@ -91,9 +91,9 @@ struct score_st* list_find(struct node_st** list, int id)
return NULL;
}
int list_destroy(struct node_st** list)
int list_destroy(struct node_st **list)
{
struct node_st* cur;
struct node_st *cur;
if (NULL == list)
return -1;

View File

@@ -11,16 +11,16 @@ struct score_st
struct node_st
{
struct score_st data;
struct node_st* next;
struct node_st *next;
};
// struct node_st *list_insert(struct node_st *list, struct score_st *data);
int list_insert(struct node_st** list, struct score_st* data);
int list_insert(struct node_st **list, struct score_st *data);
void list_show(struct node_st* list);
void list_show(struct node_st *list);
int list_delete(struct node_st** list);
int list_delete(struct node_st **list);
struct score_st* list_find(struct node_st** list, int id);
struct score_st *list_find(struct node_st **list, int id);
int list_destroy(struct node_st** list);
int list_destroy(struct node_st **list);

View File

@@ -5,10 +5,10 @@ typedef struct node_st
{
int coef;
int exp;
struct node_st* next;
struct node_st *next;
} list;
list* poly_create(int a[][2], int n)
list *poly_create(int a[][2], int n)
{
list *me, *newnode, *cur;
@@ -36,9 +36,9 @@ list* poly_create(int a[][2], int n)
return me;
}
void poly_show(list* me)
void poly_show(list *me)
{
list* cur;
list *cur;
for (cur = me->next; NULL != cur; cur = cur->next)
{
@@ -47,7 +47,7 @@ void poly_show(list* me)
printf("\n");
}
void poly_union(list* p1, list* p2)
void poly_union(list *p1, list *p2)
{
list *p, *q, *r;

View File

@@ -5,7 +5,7 @@
int main( )
{
queue* sq;
queue *sq;
datatype arr[] = {2, 34, 89, 12};
int i;

View File

@@ -4,9 +4,9 @@
#include "queue.h"
queue* qu_create( )
queue *qu_create( )
{
queue* sq;
queue *sq;
sq = malloc(sizeof(*sq));
if (NULL == sq)
@@ -18,12 +18,12 @@ queue* qu_create( )
return sq;
}
int qu_isempty(queue* sq)
int qu_isempty(queue *sq)
{
return (sq->head == sq->tail);
}
int qu_enqueue(queue* sq, datatype* x)
int qu_enqueue(queue *sq, datatype *x)
{
if ((sq->tail + 1) % MAXSIZE == sq->head)
return -1;
@@ -34,7 +34,7 @@ int qu_enqueue(queue* sq, datatype* x)
return 0;
}
int qu_dequeue(queue* sq, datatype* x)
int qu_dequeue(queue *sq, datatype *x)
{
if (qu_isempty(sq))
return -1;
@@ -45,7 +45,7 @@ int qu_dequeue(queue* sq, datatype* x)
return 0;
}
void qu_travel(queue* sq)
void qu_travel(queue *sq)
{
if (sq->head == sq->tail)
return;
@@ -61,12 +61,12 @@ void qu_travel(queue* sq)
printf("%d \n", sq->data[i]);
}
void qu_clear(queue* sq)
void qu_clear(queue *sq)
{
sq->head = sq->tail;
}
void qu_destroy(queue* sq)
void qu_destroy(queue *sq)
{
free(sq);
}

View File

@@ -12,18 +12,18 @@ typedef struct node_st
} queue;
queue* qu_create( );
queue *qu_create( );
int qu_isempty( );
int qu_enqueue(queue*, datatype*);
int qu_enqueue(queue *, datatype *);
int qu_dequeue(queue*, datatype*);
int qu_dequeue(queue *, datatype *);
void qu_travel(queue*);
void qu_travel(queue *);
void qu_clear(queue*);
void qu_clear(queue *);
void qu_destroy(queue*);
void qu_destroy(queue *);
#endif

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( )
{
QUEUE* qu;
QUEUE *qu;
struct score_st tmp;
int i, ret;

View File

@@ -1,26 +1,26 @@
#include "queue.h"
QUEUE* queue_create(int size)
QUEUE *queue_create(int size)
{
return llist_create(size);
}
int queue_en(QUEUE* ptr, const void* data)
int queue_en(QUEUE *ptr, const void *data)
{
llist_insert(ptr, data, LLIST_BACKWARD);
}
static int always_match(const void* p1, const void* p2)
static int always_match(const void *p1, const void *p2)
{
return 0;
}
int queue_de(QUEUE* ptr, void* data)
int queue_de(QUEUE *ptr, void *data)
{
return llist_fetch(ptr, (void*)0, always_match, data);
return llist_fetch(ptr, (void *)0, always_match, data);
}
void queue_destroy(QUEUE* ptr)
void queue_destroy(QUEUE *ptr)
{
llist_destroy(ptr);
}

View File

@@ -5,12 +5,12 @@
typedef LLIST QUEUE;
QUEUE* queue_create(int);
QUEUE *queue_create(int);
int queue_en(QUEUE*, const void*);
int queue_en(QUEUE *, const void *);
int queue_de(QUEUE*, void*);
int queue_de(QUEUE *, void *);
void queue_destroy(QUEUE*);
void queue_destroy(QUEUE *);
#endif

View File

@@ -6,7 +6,7 @@
int main( )
{
datatype arr[] = {19, 23, 0, 45, 67};
sqstack* st;
sqstack *st;
int i;
st = st_create( );

View File

@@ -3,9 +3,9 @@
#include "sqstack.h"
sqstack* st_create(void)
sqstack *st_create(void)
{
sqstack* st;
sqstack *st;
st = malloc(sizeof(*st));
if (NULL == st)
@@ -16,12 +16,12 @@ sqstack* st_create(void)
return st;
}
int st_isempty(sqstack* st)
int st_isempty(sqstack *st)
{
return (-1 == st->top);
}
int st_push(sqstack* st, datatype* data)
int st_push(sqstack *st, datatype *data)
{
if (MAXSIZE - 1 == st->top)
return -1;
@@ -32,7 +32,7 @@ int st_push(sqstack* st, datatype* data)
}
/* 取出栈顶元素 */
int st_pop(sqstack* st, datatype* data)
int st_pop(sqstack *st, datatype *data)
{
if (st_isempty(st))
return -1;
@@ -44,7 +44,7 @@ int st_pop(sqstack* st, datatype* data)
/* 查看栈顶元素 */
int st_top(sqstack* st, datatype* data)
int st_top(sqstack *st, datatype *data)
{
if (st_isempty(st))
return -1;
@@ -54,7 +54,7 @@ int st_top(sqstack* st, datatype* data)
return 0;
}
void st_travel(sqstack* st)
void st_travel(sqstack *st)
{
if (st_isempty(st))
return;
@@ -66,7 +66,7 @@ void st_travel(sqstack* st)
printf("\n");
}
void st_destroy(sqstack* st)
void st_destroy(sqstack *st)
{
free(st);
}

View File

@@ -11,20 +11,20 @@ typedef struct node_st
int top;
} sqstack;
sqstack* st_create(void);
sqstack *st_create(void);
int st_isempty(sqstack*);
int st_isempty(sqstack *);
int st_push(sqstack*, datatype*);
int st_push(sqstack *, datatype *);
/* 取出栈顶元素 */
int st_pop(sqstack*, datatype*);
int st_pop(sqstack *, datatype *);
/* 查看栈顶元素 */
int st_top(sqstack*, datatype*);
int st_top(sqstack *, datatype *);
void st_travel(sqstack*);
void st_travel(sqstack *);
void st_destroy(sqstack*);
void st_destroy(sqstack *);
#endif

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

View File

@@ -20,7 +20,7 @@ struct node_st
};
struct node_st* tree = NULL;
struct node_st *tree = NULL;
/**
* @brief 插入节点
@@ -35,9 +35,9 @@ struct node_st* tree = NULL;
* @param data
* @return int
*/
static int insert(struct node_st** root, struct score_st* data)
static int insert(struct node_st **root, struct score_st *data)
{
struct node_st* node;
struct node_st *node;
if (NULL == *root)
{
@@ -59,7 +59,7 @@ static int insert(struct node_st** root, struct score_st* data)
}
struct score_st* find(struct node_st* root, int id)
struct score_st *find(struct node_st *root, int id)
{
if (NULL == root)
return NULL;
@@ -72,13 +72,13 @@ struct score_st* find(struct node_st* root, int id)
return find(root->r, id);
}
static void print_s(struct score_st* d)
static void print_s(struct score_st *d)
{
printf("%d %s %d %d\n", d->id, d->name, d->math, d->chinese);
}
static void draw_(struct node_st* root, int level)
static void draw_(struct node_st *root, int level)
{
if (NULL == root)
return;
@@ -100,7 +100,7 @@ static void draw_(struct node_st* root, int level)
*D
* @param root
*/
static void draw(struct node_st* root)
static void draw(struct node_st *root)
{
draw_(root, 0);
@@ -117,7 +117,7 @@ static void draw(struct node_st* root)
* @param root
* @return int
*/
static int get_num(struct node_st* root)
static int get_num(struct node_st *root)
{
if (NULL == root)
return 0;
@@ -126,7 +126,7 @@ static int get_num(struct node_st* root)
}
static struct node_st* find_min(struct node_st* root)
static struct node_st *find_min(struct node_st *root)
{
if (NULL == root->l)
return root;
@@ -141,9 +141,9 @@ static struct node_st* find_min(struct node_st* root)
*
* @param root
*/
static void turn_left(struct node_st** root)
static void turn_left(struct node_st **root)
{
struct node_st* cur = *root;
struct node_st *cur = *root;
*root = cur->r;
cur->r = NULL;
@@ -154,7 +154,7 @@ static void turn_left(struct node_st** root)
}
static struct node_st* find_max(struct node_st* root)
static struct node_st *find_max(struct node_st *root)
{
if (NULL == root->r)
return root;
@@ -169,9 +169,9 @@ static struct node_st* find_max(struct node_st* root)
*
* @param root
*/
static void turn_right(struct node_st** root)
static void turn_right(struct node_st **root)
{
struct node_st* cur = *root;
struct node_st *cur = *root;
*root = cur->l;
cur->l = NULL;
@@ -189,7 +189,7 @@ static void turn_right(struct node_st** root)
*
* @param root
*/
static void balance(struct node_st** root)
static void balance(struct node_st **root)
{
if (NULL == *root)
return;
@@ -221,10 +221,10 @@ static void balance(struct node_st** root)
* @param root
* @param tmpid
*/
static void delete(struct node_st** root, int id)
static void delete(struct node_st **root, int id)
{
struct node_st** node = root;
struct node_st* cur;
struct node_st **node = root;
struct node_st *cur;
while (*node != NULL && (*node)->data.id != id)
{
@@ -279,16 +279,16 @@ static void travel(struct node_st *root)
*
* @param root
*/
static void travel(struct node_st* root)
static void travel(struct node_st *root)
{
if (NULL == root)
return;
int ret;
QUEUE* qu;
struct node_st* cur;
QUEUE *qu;
struct node_st *cur;
qu = queue_create(sizeof(struct node_st*));
qu = queue_create(sizeof(struct node_st *));
if (NULL == qu)
return;

View File

@@ -9,14 +9,14 @@
struct node_st
{
struct node_st* ch[26];
struct node_st *ch[26];
char desc[DESC_SIZE];
};
static int get_word(FILE* fp, char* key, char* desc)
static int get_word(FILE *fp, char *key, char *desc)
{
char buf[BUFSIZE];
char* retp;
char *retp;
int i, j;
retp = fgets(buf, BUFSIZE, fp);
@@ -36,9 +36,9 @@ static int get_word(FILE* fp, char* key, char* desc)
return 0;
}
static struct node_st* newnode( )
static struct node_st *newnode( )
{
struct node_st* node;
struct node_st *node;
int i;
node = malloc(sizeof(*node));
@@ -53,7 +53,7 @@ static struct node_st* newnode( )
return node;
}
static int insert(struct node_st** root, char* key, char* desc)
static int insert(struct node_st **root, char *key, char *desc)
{
if (NULL == *root)
{
@@ -71,7 +71,7 @@ static int insert(struct node_st** root, char* key, char* desc)
return insert((*root)->ch + *key - 'a', key + 1, desc);
}
static char* find(struct node_st* root, char* key)
static char *find(struct node_st *root, char *key)
{
if (NULL == root)
return NULL;
@@ -84,11 +84,11 @@ static char* find(struct node_st* root, char* key)
int main( )
{
struct node_st* tree;
FILE* fp;
struct node_st *tree;
FILE *fp;
char desc[DESC_SIZE] = {'\0'}, key[KEY_SIZE] = {'\0'};
int ret;
char* datap;
char *datap;
fp = fopen(FNAME, "r");
if (NULL == fp)

View File

@@ -12,10 +12,10 @@ struct node_st
};
struct node_st* tree = NULL;
struct node_st *tree = NULL;
static void draw_(struct node_st* root, int level)
static void draw_(struct node_st *root, int level)
{
if (NULL == root)
return;
@@ -37,17 +37,17 @@ static void draw_(struct node_st* root, int level)
*D
* @param root
*/
static void draw(struct node_st* root)
static void draw(struct node_st *root)
{
draw_(root, 0);
printf("\n\n");
}
static struct node_st* load_(FILE* fp)
static struct node_st *load_(FILE *fp)
{
int c;
struct node_st* root;
struct node_st *root;
c = fgetc(fp);
/* if error */
@@ -78,10 +78,10 @@ static struct node_st* load_(FILE* fp)
static struct node_st* load(const char* path)
static struct node_st *load(const char *path)
{
FILE* fp;
struct node_st* root;
FILE *fp;
struct node_st *root;
fp = fopen(path, "r");
if (NULL == fp)
@@ -96,7 +96,7 @@ static struct node_st* load(const char* path)
int main( )
{
struct node_st* root;
struct node_st *root;
root = load(FNAME);

View File

@@ -12,7 +12,7 @@ struct node_st
};
struct node_st* tree = NULL;
struct node_st *tree = NULL;
/**
* @brief 插入节点
@@ -27,9 +27,9 @@ struct node_st* tree = NULL;
* @param data
* @return int
*/
static int insert(struct node_st** root, int data)
static int insert(struct node_st **root, int data)
{
struct node_st* node;
struct node_st *node;
if (NULL == *root)
{
@@ -51,7 +51,7 @@ static int insert(struct node_st** root, int data)
}
static void draw_(struct node_st* root, int level)
static void draw_(struct node_st *root, int level)
{
if (NULL == root)
return;
@@ -73,7 +73,7 @@ static void draw_(struct node_st* root, int level)
*D
* @param root
*/
static void draw(struct node_st* root)
static void draw(struct node_st *root)
{
draw_(root, 0);
@@ -81,7 +81,7 @@ static void draw(struct node_st* root)
}
static int save_(struct node_st* root, FILE* fp)
static int save_(struct node_st *root, FILE *fp)
{
fputc('(', fp);
/* if error */
@@ -102,9 +102,9 @@ static int save_(struct node_st* root, FILE* fp)
/* if error */
}
static int save(struct node_st* root, const char* path)
static int save(struct node_st *root, const char *path)
{
FILE* fp;
FILE *fp;
fp = fopen(path, "w");
if (NULL == fp)
return -1;
@@ -122,7 +122,7 @@ int main( )
{
char arr[] = "cefadjbh";
int i;
struct score_st* datap;
struct score_st *datap;
for (i = 0; i < sizeof(arr) / sizeof(*arr) - 1; i++)
{