↩ revert:
This commit is contained in:
@@ -253,7 +253,7 @@ PenaltyExcessCharacter: 1000000
|
||||
PenaltyReturnTypeOnItsOwnLine: 120
|
||||
|
||||
# 指针和引用的对齐: Left, Right, Middle
|
||||
PointerAlignment: Left
|
||||
PointerAlignment: Right
|
||||
|
||||
# 允许重新排版注释
|
||||
ReflowComments: true
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
|
||||
int main( )
|
||||
{
|
||||
FILE* fp;
|
||||
FILE *fp;
|
||||
|
||||
fp = fopen("tmp", "r");
|
||||
if (fp == NULL)
|
||||
|
||||
@@ -2,9 +2,9 @@
|
||||
|
||||
int main(void)
|
||||
{
|
||||
int* p = NULL;
|
||||
int *p = NULL;
|
||||
int i;
|
||||
p = (int*)malloc(sizeof(int));
|
||||
p = (int *)malloc(sizeof(int));
|
||||
if (p == NULL)
|
||||
return -1;
|
||||
printf("Hello world!\n");
|
||||
|
||||
@@ -11,7 +11,7 @@ int main( )
|
||||
|
||||
int a[] = {5, 1, 7, 2, 8, 3};
|
||||
int y;
|
||||
int* p = &a[1];
|
||||
int *p = &a[1];
|
||||
|
||||
y = (*--p)++;
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
int main( )
|
||||
{
|
||||
|
||||
char* str = "hello";
|
||||
char *str = "hello";
|
||||
|
||||
printf("%d %d\n", sizeof(str), strlen(str));
|
||||
// out: 8 5
|
||||
|
||||
@@ -23,7 +23,7 @@ int main( )
|
||||
int i = 1;
|
||||
int j = 100;
|
||||
|
||||
const int* const p = &i;
|
||||
const int *const p = &i;
|
||||
|
||||
//(F) p = &j;
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ int main( )
|
||||
{
|
||||
int a[2][3] = {1, 2, 3, 4, 5, 6};
|
||||
int i, j;
|
||||
int* p = *a;
|
||||
int *p = *a;
|
||||
int(*q)[3] = a;
|
||||
|
||||
|
||||
|
||||
@@ -7,12 +7,12 @@ int main( )
|
||||
{
|
||||
int i = 1;
|
||||
|
||||
int* p = &i;
|
||||
int *p = &i;
|
||||
// 相当于
|
||||
// int *p;
|
||||
// p = &i;
|
||||
|
||||
int** q = &p;
|
||||
int **q = &p;
|
||||
|
||||
printf("i = %d\n", i);
|
||||
printf("&i = %d\n", &i);
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
int main( )
|
||||
{
|
||||
int* p;
|
||||
int *p;
|
||||
|
||||
*p = 1;
|
||||
|
||||
|
||||
@@ -5,10 +5,10 @@
|
||||
|
||||
int main( )
|
||||
{
|
||||
char* name[5] = {"Follow me", "Basic", "Great", "Fortran", "Computer"};
|
||||
char *name[5] = {"Follow me", "Basic", "Great", "Fortran", "Computer"};
|
||||
// 指针数组
|
||||
int i, j, k;
|
||||
char* tmp;
|
||||
char *tmp;
|
||||
|
||||
for (i = 0; i < 5 - 1; i++)
|
||||
{
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
void print_arr(int* p, int size)
|
||||
void print_arr(int *p, int size)
|
||||
{
|
||||
int i;
|
||||
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++)
|
||||
{
|
||||
|
||||
@@ -2,9 +2,9 @@
|
||||
#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)
|
||||
while ((*dest++ = *src++) != '\0')
|
||||
;
|
||||
@@ -12,7 +12,7 @@ char* mystrcpy(char* dest, const char* src)
|
||||
return ret;
|
||||
}
|
||||
|
||||
char* mystrncpy(char* dest, const char* src, size_t n)
|
||||
char *mystrncpy(char *dest, const char *src, size_t n)
|
||||
{
|
||||
int i;
|
||||
for (i = 0; i < n && (dest[i] = src[i]); i++)
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
#define M 3
|
||||
#define N 4
|
||||
|
||||
void print_douarr(int* p, int n)
|
||||
void print_douarr(int *p, int n)
|
||||
{
|
||||
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;
|
||||
|
||||
@@ -57,7 +57,7 @@ void find_num(int (*p)[N], int num)
|
||||
}
|
||||
#endif
|
||||
|
||||
int* find_num(int (*p)[N], int num)
|
||||
int *find_num(int (*p)[N], int num)
|
||||
{
|
||||
if (num > M - 1)
|
||||
return NULL;
|
||||
@@ -76,7 +76,7 @@ int main( )
|
||||
|
||||
// find_num(a, 2);
|
||||
|
||||
int* res;
|
||||
int *res;
|
||||
|
||||
res = find_num(a, 2);
|
||||
if (NULL != res)
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
|
||||
printf("argc = %d\n", argc);
|
||||
|
||||
@@ -18,7 +18,7 @@ int print_value(int a, int b)
|
||||
// j = tmp;
|
||||
// }
|
||||
|
||||
void swap(int* p, int* q)
|
||||
void swap(int *p, int *q)
|
||||
{
|
||||
int tmp;
|
||||
|
||||
|
||||
@@ -40,7 +40,7 @@ struct student_st
|
||||
};
|
||||
|
||||
|
||||
void func(struct simp_st* b)
|
||||
void func(struct simp_st *b)
|
||||
{
|
||||
printf("%d\n", sizeof(b));
|
||||
}
|
||||
@@ -51,7 +51,7 @@ int main( )
|
||||
|
||||
|
||||
struct simp_st a;
|
||||
struct simp_st* p = &a;
|
||||
struct simp_st *p = &a;
|
||||
|
||||
// func(a);
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
int main( )
|
||||
{
|
||||
int* p;
|
||||
int *p;
|
||||
int num = 5;
|
||||
|
||||
p = malloc(sizeof(int) * num);
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
int main( )
|
||||
{
|
||||
int* p = NULL;
|
||||
int *p = NULL;
|
||||
|
||||
p = malloc(sizeof(int));
|
||||
if (NULL == p)
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
// return;
|
||||
// }
|
||||
|
||||
void* func(int* p, int n)
|
||||
void *func(int *p, int n)
|
||||
{
|
||||
p = malloc(n);
|
||||
|
||||
@@ -24,7 +24,7 @@ void* func(int* p, int n)
|
||||
int main( )
|
||||
{
|
||||
int num = 100;
|
||||
int* p = NULL;
|
||||
int *p = NULL;
|
||||
|
||||
// func(&p, num);
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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
|
||||
@@ -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};
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
@@ -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)); \
|
||||
const typeof(((type *)0)->member) *__mptr = (ptr); \
|
||||
(type *)((char *)__mptr - offsetof(type, member)); \
|
||||
})
|
||||
|
||||
#define list_entry(ptr, type, member) container_of(ptr, type, member)
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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
|
||||
@@ -5,7 +5,7 @@
|
||||
|
||||
int main( )
|
||||
{
|
||||
list* l;
|
||||
list *l;
|
||||
datatype arr[] = {12, 9, 23, 2, 34, 6, 45};
|
||||
|
||||
l = list_create( );
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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");
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
|
||||
int main( )
|
||||
{
|
||||
queue* sq;
|
||||
queue *sq;
|
||||
datatype arr[] = {2, 34, 89, 12};
|
||||
int i;
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
@@ -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
|
||||
@@ -6,7 +6,7 @@
|
||||
int main( )
|
||||
{
|
||||
datatype arr[] = {19, 23, 0, 45, 67};
|
||||
sqstack* st;
|
||||
sqstack *st;
|
||||
int i;
|
||||
|
||||
st = st_create( );
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
@@ -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
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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++)
|
||||
{
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
int main(int argc, char** argv)
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
char buf[1024];
|
||||
int year = 2014, month = 5, day = 13;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
int main(int argc, char** argv)
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
int i;
|
||||
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
int main(int argc, char** argv)
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
FILE* fp;
|
||||
FILE *fp;
|
||||
int count;
|
||||
|
||||
if (argc < 2)
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
int main(int argc, char** argv)
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
FILE* fp;
|
||||
FILE *fp;
|
||||
|
||||
if (argc < 2)
|
||||
{
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
|
||||
int main( )
|
||||
{
|
||||
FILE* fp;
|
||||
FILE *fp;
|
||||
|
||||
fp = fopen("tmp", "r");
|
||||
if (NULL == fp)
|
||||
|
||||
@@ -2,10 +2,10 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
int main(int argc, char** argv)
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
FILE* fp;
|
||||
char* linebuf;
|
||||
FILE *fp;
|
||||
char *linebuf;
|
||||
size_t linesize;
|
||||
|
||||
if (argc < 2)
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
|
||||
int main( )
|
||||
{
|
||||
FILE* fp = NULL;
|
||||
FILE *fp = NULL;
|
||||
int count = 0;
|
||||
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
* @return int
|
||||
*/
|
||||
|
||||
int main(int argc, char** argv)
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
FILE *fps, *fpd;
|
||||
int ch;
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
* @return int
|
||||
*/
|
||||
|
||||
int main(int argc, char** argv)
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
FILE *fps, *fpd;
|
||||
char buf[BUFSIZE];
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
* @return int
|
||||
*/
|
||||
|
||||
int main(int argc, char** argv)
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
FILE *fps, *fpd;
|
||||
char buf[BUFSIZE];
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
|
||||
int main(int argc, char** argv)
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
putchar('a');
|
||||
write(1, "b", 1);
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
|
||||
#define FNAME "/tmp/out"
|
||||
|
||||
int main(int argc, char** argv)
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
int fd;
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
* time ./mycpy /etc/services /tmp/out
|
||||
*/
|
||||
|
||||
int main(int argc, char** argv)
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
int sfd, dfd;
|
||||
char buf[BUFSIZE];
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
int main(int argc, char** argv)
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
if (argc < 4)
|
||||
{
|
||||
|
||||
@@ -13,10 +13,10 @@
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
int main(int argc, char** argv)
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
time_t stamp;
|
||||
struct tm* tm;
|
||||
struct tm *tm;
|
||||
char timestr[TIMESTRSIZE];
|
||||
|
||||
time(&stamp);
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
* @return int 读到的一行数据的数据个数( n>=0 )
|
||||
* -1: 读到文件尾部或者出错
|
||||
*/
|
||||
static int read_line(int fd, unsigned char* buf)
|
||||
static int read_line(int fd, unsigned char *buf)
|
||||
{
|
||||
unsigned char c;
|
||||
int len;
|
||||
@@ -70,7 +70,7 @@ static int read_line(int fd, unsigned char* buf)
|
||||
*
|
||||
* @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=",语文,数学,英语,总分,评价"
|
||||
@@ -84,7 +84,7 @@ static void process_data(unsigned char* data_buf, unsigned char* result_buf)
|
||||
char name[100];
|
||||
int scores[3];
|
||||
int sum;
|
||||
char* levels[] = {"A+", "A", "B"};
|
||||
char *levels[] = {"A+", "A", "B"};
|
||||
int level;
|
||||
|
||||
// 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
|
||||
*/
|
||||
int main(int argc, char** argv)
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
int fd_data, fd_result;
|
||||
int len;
|
||||
|
||||
@@ -16,7 +16,7 @@ static void f3(void)
|
||||
puts("f3() is working!");
|
||||
}
|
||||
|
||||
int main(int argc, char** argv)
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
puts("Begin!");
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
|
||||
int main(int argc, char** argv)
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
if (argc < 2)
|
||||
{
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
int main(int argc, char** argv)
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
if (argc < 2)
|
||||
{
|
||||
@@ -24,9 +24,9 @@ int main(int argc, char** argv)
|
||||
exit(1);
|
||||
}
|
||||
|
||||
char* input_pass;
|
||||
struct spwd* shadowline;
|
||||
char* crypt_pass;
|
||||
char *input_pass;
|
||||
struct spwd *shadowline;
|
||||
char *crypt_pass;
|
||||
|
||||
//* getpass()函数在输入密码时不会回显密码
|
||||
input_pass = getpass("PassWord: ");
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
#include <sys/types.h>
|
||||
|
||||
// !!! 不是int
|
||||
static off_t flen(char* fname)
|
||||
static off_t flen(char *fname)
|
||||
{
|
||||
struct stat statres;
|
||||
|
||||
@@ -26,7 +26,7 @@ static off_t flen(char* fname)
|
||||
* @param argv
|
||||
* @return int
|
||||
*/
|
||||
int main(int argc, char** argv)
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
if (argc < 2)
|
||||
{
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
#include <stdlib.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
static int ftype(const char* fname)
|
||||
static int ftype(const char *fname)
|
||||
{
|
||||
struct stat statres;
|
||||
|
||||
@@ -40,7 +40,7 @@ static int ftype(const char* fname)
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
int main(int argc, char** argv)
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
if (argc < 2)
|
||||
{
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
int main(int argc, char** argv)
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
|
||||
puts(getenv("PATH"));
|
||||
|
||||
@@ -23,7 +23,7 @@ static int errfunc_(const char *errpath, int eerrno)
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
int main(int argc, char** argv)
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
glob_t globres;
|
||||
int err;
|
||||
|
||||
@@ -68,7 +68,7 @@ static void a(void)
|
||||
* @param argv
|
||||
* @return int
|
||||
*/
|
||||
int main(int argc, char** argv)
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
printf("%s():Begin.\n", __FUNCTION__);
|
||||
printf("%s():Call a().\n", __FUNCTION__);
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
int main(int argc, char** argv)
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
printf("argc = %d\n", argc);
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
int main(int argc, char** argv)
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
printf("Hello, World!\n");
|
||||
|
||||
|
||||
@@ -25,15 +25,15 @@
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
int main(int argc, char** argv)
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
time_t stamp;
|
||||
struct tm* tm;
|
||||
struct tm *tm;
|
||||
char timestr[TIMESTRSIZE];
|
||||
int c;
|
||||
char fmtstr[FMTSTRSIZE];
|
||||
fmtstr[0] = '\0';
|
||||
FILE* fp = stdout;
|
||||
FILE *fp = stdout;
|
||||
|
||||
time(&stamp);
|
||||
tm = localtime(&stamp);
|
||||
|
||||
@@ -7,9 +7,9 @@
|
||||
|
||||
#define PATHSIZE 1024
|
||||
|
||||
static int path_noloop(const char* path)
|
||||
static int path_noloop(const char *path)
|
||||
{
|
||||
char* pos;
|
||||
char *pos;
|
||||
|
||||
/**
|
||||
* @brief strrchr
|
||||
@@ -27,7 +27,7 @@ static int path_noloop(const char* path)
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int64_t mydu(const char* path)
|
||||
static int64_t mydu(const char *path)
|
||||
{
|
||||
// 优化递归
|
||||
// 将部分与递归无关的变量拿出栈,用 static 修饰
|
||||
@@ -111,7 +111,7 @@ static int64_t mydu(const char* path)
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
int main(int argc, char** argv)
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
if (argc < 2)
|
||||
{
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user