↩ 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

@@ -253,7 +253,7 @@ PenaltyExcessCharacter: 1000000
PenaltyReturnTypeOnItsOwnLine: 120 PenaltyReturnTypeOnItsOwnLine: 120
# 指针和引用的对齐: Left, Right, Middle # 指针和引用的对齐: Left, Right, Middle
PointerAlignment: Left PointerAlignment: Right
# 允许重新排版注释 # 允许重新排版注释
ReflowComments: true ReflowComments: true

View File

@@ -5,7 +5,7 @@
int main( ) int main( )
{ {
FILE* fp; FILE *fp;
fp = fopen("tmp", "r"); fp = fopen("tmp", "r");
if (fp == NULL) if (fp == NULL)

View File

@@ -2,9 +2,9 @@
int main(void) int main(void)
{ {
int* p = NULL; int *p = NULL;
int i; int i;
p = (int*)malloc(sizeof(int)); p = (int *)malloc(sizeof(int));
if (p == NULL) if (p == NULL)
return -1; return -1;
printf("Hello world!\n"); printf("Hello world!\n");

View File

@@ -11,7 +11,7 @@ int main( )
int a[] = {5, 1, 7, 2, 8, 3}; int a[] = {5, 1, 7, 2, 8, 3};
int y; int y;
int* p = &a[1]; int *p = &a[1];
y = (*--p)++; y = (*--p)++;

View File

@@ -5,7 +5,7 @@
int main( ) int main( )
{ {
char* str = "hello"; char *str = "hello";
printf("%d %d\n", sizeof(str), strlen(str)); printf("%d %d\n", sizeof(str), strlen(str));
// out: 8 5 // out: 8 5

View File

@@ -23,7 +23,7 @@ int main( )
int i = 1; int i = 1;
int j = 100; int j = 100;
const int* const p = &i; const int *const p = &i;
//(F) p = &j; //(F) p = &j;

View File

@@ -7,7 +7,7 @@ int main( )
{ {
int a[2][3] = {1, 2, 3, 4, 5, 6}; int a[2][3] = {1, 2, 3, 4, 5, 6};
int i, j; int i, j;
int* p = *a; int *p = *a;
int(*q)[3] = a; int(*q)[3] = a;

View File

@@ -7,12 +7,12 @@ int main( )
{ {
int i = 1; int i = 1;
int* p = &i; int *p = &i;
// 相当于 // 相当于
// int *p; // int *p;
// p = &i; // p = &i;
int** q = &p; int **q = &p;
printf("i = %d\n", i); printf("i = %d\n", i);
printf("&i = %d\n", &i); printf("&i = %d\n", &i);

View File

@@ -3,7 +3,7 @@
int main( ) int main( )
{ {
int* p; int *p;
*p = 1; *p = 1;

View File

@@ -5,10 +5,10 @@
int main( ) int main( )
{ {
char* name[5] = {"Follow me", "Basic", "Great", "Fortran", "Computer"}; char *name[5] = {"Follow me", "Basic", "Great", "Fortran", "Computer"};
// 指针数组 // 指针数组
int i, j, k; int i, j, k;
char* tmp; char *tmp;
for (i = 0; i < 5 - 1; i++) for (i = 0; i < 5 - 1; i++)
{ {

View File

@@ -1,7 +1,7 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
void print_arr(int* p, int size) void print_arr(int *p, int size)
{ {
int i; int i;
printf("%s:%d\n", __FUNCTION__, sizeof(p)); printf("%s:%d\n", __FUNCTION__, sizeof(p));
@@ -13,9 +13,9 @@ void print_arr(int* p, int size)
} }
void func(int* p, int size) void func(int *p, int size)
{ {
int* tmp; int *tmp;
for (int i = 0; i < size / 2; i++) for (int i = 0; i < size / 2; i++)
{ {

View File

@@ -2,9 +2,9 @@
#include <stdlib.h> #include <stdlib.h>
char* mystrcpy(char* dest, const char* src) char *mystrcpy(char *dest, const char *src)
{ {
char* ret = dest; char *ret = dest;
if (NULL != dest && NULL != src) if (NULL != dest && NULL != src)
while ((*dest++ = *src++) != '\0') while ((*dest++ = *src++) != '\0')
; ;
@@ -12,7 +12,7 @@ char* mystrcpy(char* dest, const char* src)
return ret; return ret;
} }
char* mystrncpy(char* dest, const char* src, size_t n) char *mystrncpy(char *dest, const char *src, size_t n)
{ {
int i; int i;
for (i = 0; i < n && (dest[i] = src[i]); i++) for (i = 0; i < n && (dest[i] = src[i]); i++)

View File

@@ -4,7 +4,7 @@
#define M 3 #define M 3
#define N 4 #define N 4
void print_douarr(int* p, int n) void print_douarr(int *p, int n)
{ {
int i, j; int i, j;
@@ -33,7 +33,7 @@ void print_douarr1(int (*p)[N], int m, int n)
} }
} }
float average_score(int* p, int n) float average_score(int *p, int n)
{ {
float sum = 0; float sum = 0;
@@ -57,7 +57,7 @@ void find_num(int (*p)[N], int num)
} }
#endif #endif
int* find_num(int (*p)[N], int num) int *find_num(int (*p)[N], int num)
{ {
if (num > M - 1) if (num > M - 1)
return NULL; return NULL;
@@ -76,7 +76,7 @@ int main( )
// find_num(a, 2); // find_num(a, 2);
int* res; int *res;
res = find_num(a, 2); res = find_num(a, 2);
if (NULL != res) if (NULL != res)

View File

@@ -1,7 +1,7 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
int main(int argc, char* argv[]) int main(int argc, char *argv[])
{ {
printf("argc = %d\n", argc); printf("argc = %d\n", argc);

View File

@@ -18,7 +18,7 @@ int print_value(int a, int b)
// j = tmp; // j = tmp;
// } // }
void swap(int* p, int* q) void swap(int *p, int *q)
{ {
int tmp; int tmp;

View File

@@ -40,7 +40,7 @@ struct student_st
}; };
void func(struct simp_st* b) void func(struct simp_st *b)
{ {
printf("%d\n", sizeof(b)); printf("%d\n", sizeof(b));
} }
@@ -51,7 +51,7 @@ int main( )
struct simp_st a; struct simp_st a;
struct simp_st* p = &a; struct simp_st *p = &a;
// func(a); // func(a);

View File

@@ -3,7 +3,7 @@
int main( ) int main( )
{ {
int* p; int *p;
int num = 5; int num = 5;
p = malloc(sizeof(int) * num); p = malloc(sizeof(int) * num);

View File

@@ -3,7 +3,7 @@
int main( ) int main( )
{ {
int* p = NULL; int *p = NULL;
p = malloc(sizeof(int)); p = malloc(sizeof(int));
if (NULL == p) if (NULL == p)

View File

@@ -11,7 +11,7 @@
// return; // return;
// } // }
void* func(int* p, int n) void *func(int *p, int n)
{ {
p = malloc(n); p = malloc(n);
@@ -24,7 +24,7 @@ void* func(int* p, int n)
int main( ) int main( )
{ {
int num = 100; int num = 100;
int* p = NULL; int *p = NULL;
// func(&p, num); // func(&p, num);

View File

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

View File

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

View File

@@ -12,18 +12,18 @@ typedef struct
} queue; } 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 #endif

View File

@@ -3,9 +3,9 @@
#include "sqstack.h" #include "sqstack.h"
sqstack* st_create(void) sqstack *st_create(void)
{ {
sqstack* st; sqstack *st;
st = malloc(sizeof(*st)); st = malloc(sizeof(*st));
if (NULL == st) if (NULL == st)
@@ -16,12 +16,12 @@ sqstack* st_create(void)
return st; return st;
} }
int st_isempty(sqstack* st) int st_isempty(sqstack *st)
{ {
return (-1 == st->top); return (-1 == st->top);
} }
int st_push(sqstack* st, type* data) int st_push(sqstack *st, type *data)
{ {
if (SIZE - 1 == st->top) if (SIZE - 1 == st->top)
return -1; 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)) if (st_isempty(st))
return -1; 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)) if (st_isempty(st))
return -1; return -1;
@@ -54,7 +54,7 @@ int st_top(sqstack* st, type* data)
return 0; return 0;
} }
void st_travel(sqstack* st) void st_travel(sqstack *st)
{ {
if (st_isempty(st)) if (st_isempty(st))
return; return;
@@ -66,7 +66,7 @@ void st_travel(sqstack* st)
printf("\n"); printf("\n");
} }
void st_destroy(sqstack* st) void st_destroy(sqstack *st)
{ {
free(st); free(st);
} }

View File

@@ -11,20 +11,20 @@ typedef struct node_st
int top; int top;
} sqstack; } 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 #endif

View File

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

View File

@@ -3,9 +3,9 @@
#include "sqstack.h" #include "sqstack.h"
sqstack* st_create(void) sqstack *st_create(void)
{ {
sqstack* st; sqstack *st;
st = malloc(sizeof(*st)); st = malloc(sizeof(*st));
if (NULL == st) if (NULL == st)
@@ -16,12 +16,12 @@ sqstack* st_create(void)
return st; return st;
} }
int st_isempty(sqstack* st) int st_isempty(sqstack *st)
{ {
return (-1 == st->top); return (-1 == st->top);
} }
int st_push(sqstack* st, datatype* data) int st_push(sqstack *st, datatype *data)
{ {
if (MAXSIZE - 1 == st->top) if (MAXSIZE - 1 == st->top)
return -1; 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)) if (st_isempty(st))
return -1; 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)) if (st_isempty(st))
return -1; return -1;
@@ -54,7 +54,7 @@ int st_top(sqstack* st, datatype* data)
return 0; return 0;
} }
void st_travel(sqstack* st) void st_travel(sqstack *st)
{ {
if (st_isempty(st)) if (st_isempty(st))
return; return;
@@ -66,7 +66,7 @@ void st_travel(sqstack* st)
printf("\n"); printf("\n");
} }
void st_destroy(sqstack* st) void st_destroy(sqstack *st)
{ {
free(st); free(st);
} }

View File

@@ -11,20 +11,20 @@ typedef struct node_st
int top; int top;
} sqstack; } 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 #endif

View File

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

View File

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

View File

@@ -11,26 +11,26 @@ typedef struct node_st
int last; int last;
} sqlist; } sqlist;
sqlist* sqlist_create( ); sqlist *sqlist_create( );
void sqlist_create1(sqlist** me); 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 #endif

View File

@@ -3,8 +3,8 @@
struct list_head struct list_head
{ {
struct list_head* prev; struct list_head *prev;
struct list_head* next; struct list_head *next;
}; };
#define LIST_HEAD_INIT(name) \ #define LIST_HEAD_INIT(name) \
@@ -14,9 +14,9 @@ struct list_head
#define LIST_HEAD(name) struct list_head name = LIST_HEAD_INIT(name) #define LIST_HEAD(name) struct list_head name = LIST_HEAD_INIT(name)
static inline void __list_add(struct list_head* new, static inline void __list_add(struct list_head *new,
struct list_head* prev, struct list_head *prev,
struct list_head* next) struct list_head *next)
{ {
next->prev = new; next->prev = new;
new->next = next; new->next = next;
@@ -24,7 +24,7 @@ static inline void __list_add(struct list_head* new,
prev->next = 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); __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) \ #define container_of(ptr, type, member) \
({ \ ({ \
const typeof(((type*)0)->member)* __mptr = (ptr); \ const typeof(((type *)0)->member) *__mptr = (ptr); \
(type*)((char*)__mptr - offsetof(type, member)); \ (type *)((char *)__mptr - offsetof(type, member)); \
}) })
#define list_entry(ptr, type, member) container_of(ptr, type, member) #define list_entry(ptr, type, member) container_of(ptr, type, member)

View File

@@ -14,7 +14,7 @@ struct score_st
int chinese; 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); 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 main( )
{ {
int i; int i;
struct score_st* datap; struct score_st *datap;
struct list_head* cur; struct list_head *cur;
LIST_HEAD(head); LIST_HEAD(head);

View File

@@ -4,9 +4,9 @@
#include "llist.h" #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 new = malloc(sizeof(*new)); // !!! 不是sizeof(initsize),也不是new,是*new
if (NULL == new) if (NULL == new)
@@ -20,9 +20,9 @@ LLIST* llist_create(int initsize)
return new; 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)); newnode = malloc(sizeof(*newnode));
if (NULL == newnode) if (NULL == newnode)
@@ -56,9 +56,9 @@ int llist_insert(LLIST* ptr, const void* data, int mode)
return 0; 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) 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 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; 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); node = find_(ptr, key, cmp);
if (node == &ptr->head) if (node == &ptr->head)
@@ -91,9 +91,9 @@ int llist_delete(LLIST* ptr, const void* key, llist_cmp* cmp)
return 0; 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); node = find_(ptr, key, cmp);
if (node == &ptr->head) if (node == &ptr->head)
@@ -111,15 +111,15 @@ int llist_fetch(LLIST* ptr, const void* key, llist_cmp* cmp, void* data)
return 0; 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) for (cur = ptr->head.next; cur != &ptr->head; cur = cur->next)
op(cur->data); op(cur->data);
} }
void llist_destroy(LLIST* ptr) void llist_destroy(LLIST *ptr)
{ {
struct llist_node_st *cur, *next; struct llist_node_st *cur, *next;

View File

@@ -6,9 +6,9 @@
struct llist_node_st struct llist_node_st
{ {
void* data; void *data;
struct llist_node_st* prev; struct llist_node_st *prev;
struct llist_node_st* next; struct llist_node_st *next;
}; };
typedef struct typedef struct
@@ -17,21 +17,21 @@ typedef struct
struct llist_node_st head; struct llist_node_st head;
} LLIST; } LLIST;
typedef void llist_op(const void*); typedef void llist_op(const void *);
typedef int llist_cmp(const void*, 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 #endif

View File

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

View File

@@ -4,9 +4,9 @@
#include "llist.h" #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 new = malloc(sizeof(*new)); // !!! 不是sizeof(initsize),也不是new,是*new
if (NULL == new) if (NULL == new)
@@ -19,9 +19,9 @@ LLIST* llist_create(int initsize)
return new; 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 newnode = malloc(sizeof(*newnode) + ptr->size); // -4
if (NULL == newnode) if (NULL == newnode)
@@ -51,9 +51,9 @@ int llist_insert(LLIST* ptr, const void* data, int mode)
return 0; 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) 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 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); node = find_(ptr, key, cmp);
if (node == &ptr->head) if (node == &ptr->head)
return NULL; return NULL;
@@ -74,9 +74,9 @@ void* llist_find(LLIST* ptr, const void* key, llist_cmp* cmp)
return node->data; 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); node = find_(ptr, key, cmp);
if (node == &ptr->head) if (node == &ptr->head)
@@ -89,9 +89,9 @@ int llist_delete(LLIST* ptr, const void* key, llist_cmp* cmp)
return 0; 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); node = find_(ptr, key, cmp);
if (node == &ptr->head) if (node == &ptr->head)
@@ -108,15 +108,15 @@ int llist_fetch(LLIST* ptr, const void* key, llist_cmp* cmp, void* data)
return 0; 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) for (cur = ptr->head.next; cur != &ptr->head; cur = cur->next)
op(cur->data); op(cur->data);
} }
void llist_destroy(LLIST* ptr) void llist_destroy(LLIST *ptr)
{ {
struct llist_node_st *cur, *next; struct llist_node_st *cur, *next;

View File

@@ -7,8 +7,8 @@
// !!! 变长结构体 // !!! 变长结构体
struct llist_node_st struct llist_node_st
{ {
struct llist_node_st* prev; struct llist_node_st *prev;
struct llist_node_st* next; struct llist_node_st *next;
// data要放在最后 // data要放在最后
char data[1]; // 占位符数据的起始。C99才只是[0] char data[1]; // 占位符数据的起始。C99才只是[0]
}; };
@@ -19,21 +19,21 @@ typedef struct
struct llist_node_st head; struct llist_node_st head;
} LLIST; } LLIST;
typedef void llist_op(const void*); typedef void llist_op(const void *);
typedef int llist_cmp(const void*, 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 #endif

View File

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

View File

@@ -4,15 +4,15 @@
#include "llist.h" #include "llist.h"
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);
LLIST* llist_create(int initsize) LLIST *llist_create(int initsize)
{ {
LLIST* new; LLIST *new;
new = malloc(sizeof(*new)); // !!! 不是sizeof(initsize),也不是new,是*new new = malloc(sizeof(*new)); // !!! 不是sizeof(initsize),也不是new,是*new
if (NULL == new) if (NULL == new)
@@ -31,9 +31,9 @@ LLIST* llist_create(int initsize)
return new; 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 newnode = malloc(sizeof(*newnode) + ptr->size); // -4
if (NULL == newnode) if (NULL == newnode)
@@ -63,9 +63,9 @@ int llist_insert(LLIST* ptr, const void* data, int mode)
return 0; 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) 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 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); node = find_(ptr, key, cmp);
if (node == &ptr->head) if (node == &ptr->head)
return NULL; return NULL;
@@ -86,9 +86,9 @@ void* llist_find(LLIST* ptr, const void* key, llist_cmp* cmp)
return node->data; 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); node = find_(ptr, key, cmp);
if (node == &ptr->head) if (node == &ptr->head)
@@ -101,9 +101,9 @@ int llist_delete(LLIST* ptr, const void* key, llist_cmp* cmp)
return 0; 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); node = find_(ptr, key, cmp);
if (node == &ptr->head) if (node == &ptr->head)
@@ -120,15 +120,15 @@ int llist_fetch(LLIST* ptr, const void* key, llist_cmp* cmp, void* data)
return 0; 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) for (cur = ptr->head.next; cur != &ptr->head; cur = cur->next)
op(cur->data); op(cur->data);
} }
void llist_destroy(LLIST* ptr) void llist_destroy(LLIST *ptr)
{ {
struct llist_node_st *cur, *next; struct llist_node_st *cur, *next;

View File

@@ -4,14 +4,14 @@
#define LLIST_FORWARD 1 #define LLIST_FORWARD 1
#define LLIST_BACKWARD 2 #define LLIST_BACKWARD 2
typedef void llist_op(const void*); typedef void llist_op(const void *);
typedef int llist_cmp(const void*, const void*); typedef int llist_cmp(const void *, const void *);
// !!! 变长结构体 // !!! 变长结构体
struct llist_node_st struct llist_node_st
{ {
struct llist_node_st* prev; struct llist_node_st *prev;
struct llist_node_st* next; struct llist_node_st *next;
// data要放在最后 // data要放在最后
char data[1]; // 占位符数据的起始。C99才只是[0] char data[1]; // 占位符数据的起始。C99才只是[0]
}; };
@@ -21,18 +21,18 @@ typedef struct llist_head
int size; int size;
struct llist_node_st head; struct llist_node_st head;
int (*insert)(struct llist_head*, const void*, int); int (*insert)(struct llist_head *, const void *, int);
void* (*find)(struct llist_head*, const void*, llist_cmp*); void *(*find)(struct llist_head *, const void *, llist_cmp *);
int (*delete)(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*); int (*fetch)(struct llist_head *, const void *, llist_cmp *, void *);
void (*travel)(struct llist_head*, llist_op*); void (*travel)(struct llist_head *, llist_op *);
} LLIST; } LLIST;
LLIST* llist_create(int initsize); LLIST *llist_create(int initsize);
void llist_destroy(LLIST* ptr); void llist_destroy(LLIST *ptr);
#endif #endif

View File

@@ -14,25 +14,25 @@ struct score_st
int chinese; 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); 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 int *k = key;
const struct score_st* r = record; const struct score_st *r = record;
return (*k - r->id); 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 char *k = key;
const struct score_st* r = record; const struct score_st *r = record;
return strcmp(k, r->name); return strcmp(k, r->name);
} }
@@ -40,7 +40,7 @@ int name_cmp(const void* key, const void* record)
int main( ) int main( )
{ {
LLIST* handler; LLIST *handler;
int i, ret; int i, ret;
struct score_st tmp; struct score_st tmp;

View File

@@ -7,8 +7,8 @@
// !!! 变长结构体 // !!! 变长结构体
struct llist_node_st struct llist_node_st
{ {
struct llist_node_st* prev; struct llist_node_st *prev;
struct llist_node_st* next; struct llist_node_st *next;
// data要放在最后 // data要放在最后
char data[1]; // 占位符数据的起始。C99才只是[0] char data[1]; // 占位符数据的起始。C99才只是[0]
}; };
@@ -19,9 +19,9 @@ struct llist_head_st
struct llist_node_st head; 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 new = malloc(sizeof(*new)); // !!! 不是sizeof(initsize),也不是new,是*new
if (NULL == new) if (NULL == new)
@@ -34,10 +34,10 @@ LLIST* llist_create(int initsize)
return new; 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_node_st *newnode;
struct llist_head_st* ptr = p; struct llist_head_st *ptr = p;
newnode = malloc(sizeof(*newnode) + ptr->size); // -4 newnode = malloc(sizeof(*newnode) + ptr->size); // -4
if (NULL == newnode) if (NULL == newnode)
@@ -67,11 +67,11 @@ int llist_insert(LLIST* p, const void* data, int mode)
return 0; return 0;
} }
static struct llist_node_st* find_(struct llist_head_st* ptr, static struct llist_node_st *find_(struct llist_head_st *ptr,
const void* key, const void *key,
llist_cmp* cmp) llist_cmp *cmp)
{ {
struct llist_node_st* cur; struct llist_node_st *cur;
for (cur = ptr->head.next; cur != &ptr->head; cur = cur->next) 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 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_head_st *ptr = p;
struct llist_node_st* node; struct llist_node_st *node;
node = find_(ptr, key, cmp); node = find_(ptr, key, cmp);
if (node == &ptr->head) if (node == &ptr->head)
return NULL; return NULL;
@@ -93,10 +93,10 @@ void* llist_find(LLIST* p, const void* key, llist_cmp* cmp)
return node->data; 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_head_st *ptr = p;
struct llist_node_st* node; struct llist_node_st *node;
node = find_(ptr, key, cmp); node = find_(ptr, key, cmp);
if (node == &ptr->head) if (node == &ptr->head)
@@ -109,10 +109,10 @@ int llist_delete(LLIST* p, const void* key, llist_cmp* cmp)
return 0; 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_head_st *ptr = p;
struct llist_node_st* node; struct llist_node_st *node;
node = find_(ptr, key, cmp); node = find_(ptr, key, cmp);
if (node == &ptr->head) if (node == &ptr->head)
@@ -129,18 +129,18 @@ int llist_fetch(LLIST* p, const void* key, llist_cmp* cmp, void* data)
return 0; 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_head_st *ptr = p;
struct llist_node_st* cur; struct llist_node_st *cur;
for (cur = ptr->head.next; cur != &ptr->head; cur = cur->next) for (cur = ptr->head.next; cur != &ptr->head; cur = cur->next)
op(cur->data); 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; struct llist_node_st *cur, *next;
for (cur = ptr->head.next; cur != &ptr->head; cur = next) for (cur = ptr->head.next; cur != &ptr->head; cur = next)

View File

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

View File

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

View File

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

View File

@@ -6,21 +6,21 @@ typedef int datatype;
typedef struct node_st typedef struct node_st
{ {
datatype data; datatype data;
struct node_st* next; struct node_st *next;
} list; } list;
list* list_create( ); list *list_create( );
int list_insert_at(list* me, int i, datatype* data); 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);
int list_delete_at(list* me, int i, datatype* data); int list_delete_at(list *me, int i, datatype *data);
int list_delete(list* me, 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_display(list *me);
void list_destroy(list* me); void list_destroy(list *me);
#endif #endif

View File

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

View File

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

View File

@@ -6,7 +6,7 @@
int main( ) int main( )
{ {
int i, ret; int i, ret;
struct node_st* list = NULL; struct node_st *list = NULL;
struct score_st tmp; struct score_st tmp;
for (i = 0; i < 7; i++) for (i = 0; i < 7; i++)
@@ -28,7 +28,7 @@ int main( )
printf("\n\n"); printf("\n\n");
int id = 13; int id = 13;
struct score_st* ptr; struct score_st *ptr;
ptr = list_find(&list, id); ptr = list_find(&list, id);
if (NULL == ptr) if (NULL == ptr)
printf("Can not find!\n"); 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 #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)); new = malloc(sizeof(*new));
if (NULL == new) if (NULL == new)
@@ -36,9 +36,9 @@ int list_insert(struct node_st** list, struct score_st* data)
return 0; 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) 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) if (NULL == *list)
return -1; return -1;
@@ -66,9 +66,9 @@ int list_delete(struct node_st** list)
return 0; 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) if (NULL == *list)
return NULL; return NULL;
@@ -91,9 +91,9 @@ struct score_st* list_find(struct node_st** list, int id)
return NULL; 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) if (NULL == list)
return -1; return -1;

View File

@@ -11,16 +11,16 @@ struct score_st
struct node_st struct node_st
{ {
struct score_st data; 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); // 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 coef;
int exp; int exp;
struct node_st* next; struct node_st *next;
} list; } list;
list* poly_create(int a[][2], int n) list *poly_create(int a[][2], int n)
{ {
list *me, *newnode, *cur; list *me, *newnode, *cur;
@@ -36,9 +36,9 @@ list* poly_create(int a[][2], int n)
return me; 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) for (cur = me->next; NULL != cur; cur = cur->next)
{ {
@@ -47,7 +47,7 @@ void poly_show(list* me)
printf("\n"); printf("\n");
} }
void poly_union(list* p1, list* p2) void poly_union(list *p1, list *p2)
{ {
list *p, *q, *r; list *p, *q, *r;

View File

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

View File

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

View File

@@ -12,18 +12,18 @@ typedef struct node_st
} queue; } 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 #endif

View File

@@ -4,9 +4,9 @@
#include "llist.h" #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 new = malloc(sizeof(*new)); // !!! 不是sizeof(initsize),也不是new,是*new
if (NULL == new) if (NULL == new)
@@ -19,9 +19,9 @@ LLIST* llist_create(int initsize)
return new; 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 newnode = malloc(sizeof(*newnode) + ptr->size); // -4
if (NULL == newnode) if (NULL == newnode)
@@ -51,9 +51,9 @@ int llist_insert(LLIST* ptr, const void* data, int mode)
return 0; 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) 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 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); node = find_(ptr, key, cmp);
if (node == &ptr->head) if (node == &ptr->head)
return NULL; return NULL;
@@ -74,9 +74,9 @@ void* llist_find(LLIST* ptr, const void* key, llist_cmp* cmp)
return node->data; 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); node = find_(ptr, key, cmp);
if (node == &ptr->head) if (node == &ptr->head)
@@ -89,9 +89,9 @@ int llist_delete(LLIST* ptr, const void* key, llist_cmp* cmp)
return 0; 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); node = find_(ptr, key, cmp);
if (node == &ptr->head) if (node == &ptr->head)
@@ -108,15 +108,15 @@ int llist_fetch(LLIST* ptr, const void* key, llist_cmp* cmp, void* data)
return 0; 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) for (cur = ptr->head.next; cur != &ptr->head; cur = cur->next)
op(cur->data); op(cur->data);
} }
void llist_destroy(LLIST* ptr) void llist_destroy(LLIST *ptr)
{ {
struct llist_node_st *cur, *next; struct llist_node_st *cur, *next;

View File

@@ -7,8 +7,8 @@
// !!! 变长结构体 // !!! 变长结构体
struct llist_node_st struct llist_node_st
{ {
struct llist_node_st* prev; struct llist_node_st *prev;
struct llist_node_st* next; struct llist_node_st *next;
// data要放在最后 // data要放在最后
char data[1]; // 占位符数据的起始。C99才只是[0] char data[1]; // 占位符数据的起始。C99才只是[0]
}; };
@@ -19,21 +19,21 @@ typedef struct
struct llist_node_st head; struct llist_node_st head;
} LLIST; } LLIST;
typedef void llist_op(const void*); typedef void llist_op(const void *);
typedef int llist_cmp(const void*, 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 #endif

View File

@@ -13,16 +13,16 @@ struct score_st
int chinese; 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); 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; struct score_st tmp;
int i, ret; int i, ret;

View File

@@ -1,26 +1,26 @@
#include "queue.h" #include "queue.h"
QUEUE* queue_create(int size) QUEUE *queue_create(int size)
{ {
return llist_create(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); 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; 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); llist_destroy(ptr);
} }

View File

@@ -5,12 +5,12 @@
typedef LLIST QUEUE; 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 #endif

View File

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

View File

@@ -3,9 +3,9 @@
#include "sqstack.h" #include "sqstack.h"
sqstack* st_create(void) sqstack *st_create(void)
{ {
sqstack* st; sqstack *st;
st = malloc(sizeof(*st)); st = malloc(sizeof(*st));
if (NULL == st) if (NULL == st)
@@ -16,12 +16,12 @@ sqstack* st_create(void)
return st; return st;
} }
int st_isempty(sqstack* st) int st_isempty(sqstack *st)
{ {
return (-1 == st->top); return (-1 == st->top);
} }
int st_push(sqstack* st, datatype* data) int st_push(sqstack *st, datatype *data)
{ {
if (MAXSIZE - 1 == st->top) if (MAXSIZE - 1 == st->top)
return -1; 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)) if (st_isempty(st))
return -1; 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)) if (st_isempty(st))
return -1; return -1;
@@ -54,7 +54,7 @@ int st_top(sqstack* st, datatype* data)
return 0; return 0;
} }
void st_travel(sqstack* st) void st_travel(sqstack *st)
{ {
if (st_isempty(st)) if (st_isempty(st))
return; return;
@@ -66,7 +66,7 @@ void st_travel(sqstack* st)
printf("\n"); printf("\n");
} }
void st_destroy(sqstack* st) void st_destroy(sqstack *st)
{ {
free(st); free(st);
} }

View File

@@ -11,20 +11,20 @@ typedef struct node_st
int top; int top;
} sqstack; } 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 #endif

View File

@@ -4,9 +4,9 @@
#include "llist.h" #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 new = malloc(sizeof(*new)); // !!! 不是sizeof(initsize),也不是new,是*new
if (NULL == new) if (NULL == new)
@@ -19,9 +19,9 @@ LLIST* llist_create(int initsize)
return new; 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 newnode = malloc(sizeof(*newnode) + ptr->size); // -4
if (NULL == newnode) if (NULL == newnode)
@@ -51,9 +51,9 @@ int llist_insert(LLIST* ptr, const void* data, int mode)
return 0; 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) 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 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); node = find_(ptr, key, cmp);
if (node == &ptr->head) if (node == &ptr->head)
return NULL; return NULL;
@@ -74,9 +74,9 @@ void* llist_find(LLIST* ptr, const void* key, llist_cmp* cmp)
return node->data; 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); node = find_(ptr, key, cmp);
if (node == &ptr->head) if (node == &ptr->head)
@@ -89,9 +89,9 @@ int llist_delete(LLIST* ptr, const void* key, llist_cmp* cmp)
return 0; 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); node = find_(ptr, key, cmp);
if (node == &ptr->head) if (node == &ptr->head)
@@ -108,15 +108,15 @@ int llist_fetch(LLIST* ptr, const void* key, llist_cmp* cmp, void* data)
return 0; 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) for (cur = ptr->head.next; cur != &ptr->head; cur = cur->next)
op(cur->data); op(cur->data);
} }
void llist_destroy(LLIST* ptr) void llist_destroy(LLIST *ptr)
{ {
struct llist_node_st *cur, *next; struct llist_node_st *cur, *next;

View File

@@ -7,8 +7,8 @@
// !!! 变长结构体 // !!! 变长结构体
struct llist_node_st struct llist_node_st
{ {
struct llist_node_st* prev; struct llist_node_st *prev;
struct llist_node_st* next; struct llist_node_st *next;
// data要放在最后 // data要放在最后
char data[1]; // 占位符数据的起始。C99才只是[0] char data[1]; // 占位符数据的起始。C99才只是[0]
}; };
@@ -19,21 +19,21 @@ typedef struct
struct llist_node_st head; struct llist_node_st head;
} LLIST; } LLIST;
typedef void llist_op(const void*); typedef void llist_op(const void *);
typedef int llist_cmp(const void*, 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 #endif

View File

@@ -13,16 +13,16 @@ struct score_st
int chinese; 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); printf("%d %s %d %d\n", r->id, r->name, r->math, r->chinese);
} }
int main( ) int main( )
{ {
STACK* st; STACK *st;
struct score_st tmp; struct score_st tmp;
int i, ret; int i, ret;

View File

@@ -2,28 +2,28 @@
#include "stack.h" #include "stack.h"
LLIST* stack_create(int initsize) LLIST *stack_create(int initsize)
{ {
return llist_create(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); 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; 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); llist_destroy(ptr);
} }

View File

@@ -5,12 +5,12 @@
typedef LLIST STACK; 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 #endif

View File

@@ -20,7 +20,7 @@ struct node_st
}; };
struct node_st* tree = NULL; struct node_st *tree = NULL;
/** /**
* @brief 插入节点 * @brief 插入节点
@@ -35,9 +35,9 @@ struct node_st* tree = NULL;
* @param data * @param data
* @return int * @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) 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) if (NULL == root)
return NULL; return NULL;
@@ -72,13 +72,13 @@ struct score_st* find(struct node_st* root, int id)
return find(root->r, 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); 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) if (NULL == root)
return; return;
@@ -100,7 +100,7 @@ static void draw_(struct node_st* root, int level)
*D *D
* @param root * @param root
*/ */
static void draw(struct node_st* root) static void draw(struct node_st *root)
{ {
draw_(root, 0); draw_(root, 0);
@@ -117,7 +117,7 @@ static void draw(struct node_st* root)
* @param root * @param root
* @return int * @return int
*/ */
static int get_num(struct node_st* root) static int get_num(struct node_st *root)
{ {
if (NULL == root) if (NULL == root)
return 0; 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) if (NULL == root->l)
return root; return root;
@@ -141,9 +141,9 @@ static struct node_st* find_min(struct node_st* root)
* *
* @param 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; *root = cur->r;
cur->r = NULL; 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) if (NULL == root->r)
return root; return root;
@@ -169,9 +169,9 @@ static struct node_st* find_max(struct node_st* root)
* *
* @param 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; *root = cur->l;
cur->l = NULL; cur->l = NULL;
@@ -189,7 +189,7 @@ static void turn_right(struct node_st** root)
* *
* @param root * @param root
*/ */
static void balance(struct node_st** root) static void balance(struct node_st **root)
{ {
if (NULL == *root) if (NULL == *root)
return; return;
@@ -221,10 +221,10 @@ static void balance(struct node_st** root)
* @param root * @param root
* @param tmpid * @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 **node = root;
struct node_st* cur; struct node_st *cur;
while (*node != NULL && (*node)->data.id != id) while (*node != NULL && (*node)->data.id != id)
{ {
@@ -279,16 +279,16 @@ static void travel(struct node_st *root)
* *
* @param root * @param root
*/ */
static void travel(struct node_st* root) static void travel(struct node_st *root)
{ {
if (NULL == root) if (NULL == root)
return; return;
int ret; int ret;
QUEUE* qu; QUEUE *qu;
struct node_st* cur; struct node_st *cur;
qu = queue_create(sizeof(struct node_st*)); qu = queue_create(sizeof(struct node_st *));
if (NULL == qu) if (NULL == qu)
return; return;

View File

@@ -9,14 +9,14 @@
struct node_st struct node_st
{ {
struct node_st* ch[26]; struct node_st *ch[26];
char desc[DESC_SIZE]; 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 buf[BUFSIZE];
char* retp; char *retp;
int i, j; int i, j;
retp = fgets(buf, BUFSIZE, fp); retp = fgets(buf, BUFSIZE, fp);
@@ -36,9 +36,9 @@ static int get_word(FILE* fp, char* key, char* desc)
return 0; return 0;
} }
static struct node_st* newnode( ) static struct node_st *newnode( )
{ {
struct node_st* node; struct node_st *node;
int i; int i;
node = malloc(sizeof(*node)); node = malloc(sizeof(*node));
@@ -53,7 +53,7 @@ static struct node_st* newnode( )
return node; 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) 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); 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) if (NULL == root)
return NULL; return NULL;
@@ -84,11 +84,11 @@ static char* find(struct node_st* root, char* key)
int main( ) int main( )
{ {
struct node_st* tree; struct node_st *tree;
FILE* fp; FILE *fp;
char desc[DESC_SIZE] = {'\0'}, key[KEY_SIZE] = {'\0'}; char desc[DESC_SIZE] = {'\0'}, key[KEY_SIZE] = {'\0'};
int ret; int ret;
char* datap; char *datap;
fp = fopen(FNAME, "r"); fp = fopen(FNAME, "r");
if (NULL == fp) 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) if (NULL == root)
return; return;
@@ -37,17 +37,17 @@ static void draw_(struct node_st* root, int level)
*D *D
* @param root * @param root
*/ */
static void draw(struct node_st* root) static void draw(struct node_st *root)
{ {
draw_(root, 0); draw_(root, 0);
printf("\n\n"); printf("\n\n");
} }
static struct node_st* load_(FILE* fp) static struct node_st *load_(FILE *fp)
{ {
int c; int c;
struct node_st* root; struct node_st *root;
c = fgetc(fp); c = fgetc(fp);
/* if error */ /* 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; FILE *fp;
struct node_st* root; struct node_st *root;
fp = fopen(path, "r"); fp = fopen(path, "r");
if (NULL == fp) if (NULL == fp)
@@ -96,7 +96,7 @@ static struct node_st* load(const char* path)
int main( ) int main( )
{ {
struct node_st* root; struct node_st *root;
root = load(FNAME); root = load(FNAME);

View File

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

View File

@@ -1,7 +1,7 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
int main(int argc, char** argv) int main(int argc, char **argv)
{ {
char buf[1024]; char buf[1024];
int year = 2014, month = 5, day = 13; int year = 2014, month = 5, day = 13;

View File

@@ -1,7 +1,7 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
int main(int argc, char** argv) int main(int argc, char **argv)
{ {
int i; int i;

View File

@@ -1,9 +1,9 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
int main(int argc, char** argv) int main(int argc, char **argv)
{ {
FILE* fp; FILE *fp;
int count; int count;
if (argc < 2) if (argc < 2)

View File

@@ -1,9 +1,9 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
int main(int argc, char** argv) int main(int argc, char **argv)
{ {
FILE* fp; FILE *fp;
if (argc < 2) if (argc < 2)
{ {

View File

@@ -5,7 +5,7 @@
int main( ) int main( )
{ {
FILE* fp; FILE *fp;
fp = fopen("tmp", "r"); fp = fopen("tmp", "r");
if (NULL == fp) if (NULL == fp)

View File

@@ -2,10 +2,10 @@
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
int main(int argc, char** argv) int main(int argc, char **argv)
{ {
FILE* fp; FILE *fp;
char* linebuf; char *linebuf;
size_t linesize; size_t linesize;
if (argc < 2) if (argc < 2)

View File

@@ -5,7 +5,7 @@
int main( ) int main( )
{ {
FILE* fp = NULL; FILE *fp = NULL;
int count = 0; int count = 0;

View File

@@ -9,7 +9,7 @@
* @return int * @return int
*/ */
int main(int argc, char** argv) int main(int argc, char **argv)
{ {
FILE *fps, *fpd; FILE *fps, *fpd;
int ch; int ch;

View File

@@ -11,7 +11,7 @@
* @return int * @return int
*/ */
int main(int argc, char** argv) int main(int argc, char **argv)
{ {
FILE *fps, *fpd; FILE *fps, *fpd;
char buf[BUFSIZE]; char buf[BUFSIZE];

View File

@@ -11,7 +11,7 @@
* @return int * @return int
*/ */
int main(int argc, char** argv) int main(int argc, char **argv)
{ {
FILE *fps, *fpd; FILE *fps, *fpd;
char buf[BUFSIZE]; char buf[BUFSIZE];

View File

@@ -2,7 +2,7 @@
#include <stdlib.h> #include <stdlib.h>
#include <unistd.h> #include <unistd.h>
int main(int argc, char** argv) int main(int argc, char **argv)
{ {
putchar('a'); putchar('a');
write(1, "b", 1); write(1, "b", 1);

View File

@@ -5,7 +5,7 @@
#define FNAME "/tmp/out" #define FNAME "/tmp/out"
int main(int argc, char** argv) int main(int argc, char **argv)
{ {
int fd; int fd;

View File

@@ -10,7 +10,7 @@
* time ./mycpy /etc/services /tmp/out * time ./mycpy /etc/services /tmp/out
*/ */
int main(int argc, char** argv) int main(int argc, char **argv)
{ {
int sfd, dfd; int sfd, dfd;
char buf[BUFSIZE]; char buf[BUFSIZE];

View File

@@ -14,7 +14,7 @@
* *
* @return int * @return int
*/ */
int main(int argc, char** argv) int main(int argc, char **argv)
{ {
if (argc < 4) if (argc < 4)
{ {

View File

@@ -13,10 +13,10 @@
* *
* @return int * @return int
*/ */
int main(int argc, char** argv) int main(int argc, char **argv)
{ {
time_t stamp; time_t stamp;
struct tm* tm; struct tm *tm;
char timestr[TIMESTRSIZE]; char timestr[TIMESTRSIZE];
time(&stamp); time(&stamp);

View File

@@ -22,7 +22,7 @@
* @return int 读到的一行数据的数据个数( n>=0 ) * @return int 读到的一行数据的数据个数( n>=0 )
* -1: 读到文件尾部或者出错 * -1: 读到文件尾部或者出错
*/ */
static int read_line(int fd, unsigned char* buf) static int read_line(int fd, unsigned char *buf)
{ {
unsigned char c; unsigned char c;
int len; int len;
@@ -70,7 +70,7 @@ static int read_line(int fd, unsigned char* buf)
* *
* @return int * @return int
*/ */
static void process_data(unsigned char* data_buf, unsigned char* result_buf) static void process_data(unsigned char *data_buf, unsigned char *result_buf)
{ {
/** /**
* eg1: data_buf=",语文,数学,英语,总分,评价" * eg1: data_buf=",语文,数学,英语,总分,评价"
@@ -84,7 +84,7 @@ static void process_data(unsigned char* data_buf, unsigned char* result_buf)
char name[100]; char name[100];
int scores[3]; int scores[3];
int sum; int sum;
char* levels[] = {"A+", "A", "B"}; char *levels[] = {"A+", "A", "B"};
int level; int level;
// debug("data_buf[0]: %x\n", data_buf[0]); // debug("data_buf[0]: %x\n", data_buf[0]);
@@ -146,7 +146,7 @@ static void process_data(unsigned char* data_buf, unsigned char* result_buf)
* *
* @return int * @return int
*/ */
int main(int argc, char** argv) int main(int argc, char **argv)
{ {
int fd_data, fd_result; int fd_data, fd_result;
int len; int len;

View File

@@ -16,7 +16,7 @@ static void f3(void)
puts("f3() is working!"); puts("f3() is working!");
} }
int main(int argc, char** argv) int main(int argc, char **argv)
{ {
puts("Begin!"); puts("Begin!");

View File

@@ -5,7 +5,7 @@
#include <sys/types.h> #include <sys/types.h>
#include <unistd.h> #include <unistd.h>
int main(int argc, char** argv) int main(int argc, char **argv)
{ {
if (argc < 2) if (argc < 2)
{ {

View File

@@ -16,7 +16,7 @@
* *
* @return int * @return int
*/ */
int main(int argc, char** argv) int main(int argc, char **argv)
{ {
if (argc < 2) if (argc < 2)
{ {
@@ -24,9 +24,9 @@ int main(int argc, char** argv)
exit(1); exit(1);
} }
char* input_pass; char *input_pass;
struct spwd* shadowline; struct spwd *shadowline;
char* crypt_pass; char *crypt_pass;
//* getpass()函数在输入密码时不会回显密码 //* getpass()函数在输入密码时不会回显密码
input_pass = getpass("PassWord: "); input_pass = getpass("PassWord: ");

View File

@@ -4,7 +4,7 @@
#include <sys/types.h> #include <sys/types.h>
// !!! 不是int // !!! 不是int
static off_t flen(char* fname) static off_t flen(char *fname)
{ {
struct stat statres; struct stat statres;
@@ -26,7 +26,7 @@ static off_t flen(char* fname)
* @param argv * @param argv
* @return int * @return int
*/ */
int main(int argc, char** argv) int main(int argc, char **argv)
{ {
if (argc < 2) if (argc < 2)
{ {

View File

@@ -2,7 +2,7 @@
#include <stdlib.h> #include <stdlib.h>
#include <sys/stat.h> #include <sys/stat.h>
static int ftype(const char* fname) static int ftype(const char *fname)
{ {
struct stat statres; struct stat statres;
@@ -40,7 +40,7 @@ static int ftype(const char* fname)
* *
* @return int * @return int
*/ */
int main(int argc, char** argv) int main(int argc, char **argv)
{ {
if (argc < 2) if (argc < 2)
{ {

View File

@@ -1,7 +1,7 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
int main(int argc, char** argv) int main(int argc, char **argv)
{ {
puts(getenv("PATH")); puts(getenv("PATH"));

View File

@@ -23,7 +23,7 @@ static int errfunc_(const char *errpath, int eerrno)
* *
* @return int * @return int
*/ */
int main(int argc, char** argv) int main(int argc, char **argv)
{ {
glob_t globres; glob_t globres;
int err; int err;

View File

@@ -68,7 +68,7 @@ static void a(void)
* @param argv * @param argv
* @return int * @return int
*/ */
int main(int argc, char** argv) int main(int argc, char **argv)
{ {
printf("%s():Begin.\n", __FUNCTION__); printf("%s():Begin.\n", __FUNCTION__);
printf("%s():Call a().\n", __FUNCTION__); printf("%s():Call a().\n", __FUNCTION__);

View File

@@ -1,7 +1,7 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
int main(int argc, char** argv) int main(int argc, char **argv)
{ {
printf("argc = %d\n", argc); printf("argc = %d\n", argc);

View File

@@ -1,7 +1,7 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
int main(int argc, char** argv) int main(int argc, char **argv)
{ {
printf("Hello, World!\n"); printf("Hello, World!\n");

View File

@@ -25,15 +25,15 @@
* *
* @return int * @return int
*/ */
int main(int argc, char** argv) int main(int argc, char **argv)
{ {
time_t stamp; time_t stamp;
struct tm* tm; struct tm *tm;
char timestr[TIMESTRSIZE]; char timestr[TIMESTRSIZE];
int c; int c;
char fmtstr[FMTSTRSIZE]; char fmtstr[FMTSTRSIZE];
fmtstr[0] = '\0'; fmtstr[0] = '\0';
FILE* fp = stdout; FILE *fp = stdout;
time(&stamp); time(&stamp);
tm = localtime(&stamp); tm = localtime(&stamp);

View File

@@ -7,9 +7,9 @@
#define PATHSIZE 1024 #define PATHSIZE 1024
static int path_noloop(const char* path) static int path_noloop(const char *path)
{ {
char* pos; char *pos;
/** /**
* @brief strrchr * @brief strrchr
@@ -27,7 +27,7 @@ static int path_noloop(const char* path)
return 1; return 1;
} }
static int64_t mydu(const char* path) static int64_t mydu(const char *path)
{ {
// 优化递归 // 优化递归
// 将部分与递归无关的变量拿出栈,用 static 修饰 // 将部分与递归无关的变量拿出栈,用 static 修饰
@@ -111,7 +111,7 @@ static int64_t mydu(const char* path)
* *
* @return int * @return int
*/ */
int main(int argc, char** argv) int main(int argc, char **argv)
{ {
if (argc < 2) if (argc < 2)
{ {

Some files were not shown because too many files have changed in this diff Show More