🌈 style:

This commit is contained in:
lzy
2024-05-26 15:39:14 +08:00
parent 6f28a3384a
commit a57bbdb4c1
156 changed files with 765 additions and 770 deletions

View File

@@ -3,13 +3,13 @@
#include "queue.h"
int main()
int main( )
{
queue *sq;
queue* sq;
datatype arr[] = {2, 34, 89, 12};
int i;
sq = qu_create();
sq = qu_create( );
if (NULL == sq)
exit(1);

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_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()
int main( )
{
QUEUE *qu;
QUEUE* qu;
struct score_st tmp;
int i, ret;
@@ -34,8 +34,8 @@ int main()
{
tmp.id = i;
snprintf(tmp.name, NAMESIZE, "stu%d", i);
tmp.math = rand() % 100;
tmp.chinese = rand() % 100;
tmp.math = rand( ) % 100;
tmp.chinese = rand( ) % 100;
if (0 != queue_en(qu, &tmp))
break;

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