🌈 style:
This commit is contained in:
@@ -253,7 +253,7 @@ PenaltyExcessCharacter: 1000000
|
||||
PenaltyReturnTypeOnItsOwnLine: 120
|
||||
|
||||
# 指针和引用的对齐: Left, Right, Middle
|
||||
PointerAlignment: Right
|
||||
PointerAlignment: Left
|
||||
|
||||
# 允许重新排版注释
|
||||
ReflowComments: true
|
||||
@@ -290,7 +290,7 @@ SpaceBeforeRangeBasedForLoopColon: true
|
||||
SpaceBeforeSquareBrackets: false
|
||||
|
||||
# 在空的圆括号中添加空格
|
||||
SpaceInEmptyParentheses: false
|
||||
SpaceInEmptyParentheses: true
|
||||
|
||||
# 在尾随的评论前添加的空格数(只适用于//)
|
||||
SpacesBeforeTrailingComments: 3
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <errno.h>
|
||||
#include <string.h>
|
||||
|
||||
int main()
|
||||
int main( )
|
||||
{
|
||||
FILE *fp;
|
||||
FILE* fp;
|
||||
|
||||
fp = fopen("tmp", "r");
|
||||
if (fp == NULL)
|
||||
|
||||
@@ -2,9 +2,9 @@
|
||||
|
||||
int main(void)
|
||||
{
|
||||
int *p = NULL;
|
||||
int i;
|
||||
p = (int *)malloc(sizeof(int));
|
||||
int* p = NULL;
|
||||
int i;
|
||||
p = (int*)malloc(sizeof(int));
|
||||
if (p == NULL)
|
||||
return -1;
|
||||
printf("Hello world!\n");
|
||||
|
||||
@@ -96,10 +96,10 @@ void print_star(void)
|
||||
printf("[%s]i=%d\n", __FUNCTION__, i);
|
||||
}
|
||||
|
||||
int main()
|
||||
int main( )
|
||||
{
|
||||
for (i = 0; i < 5; i++)
|
||||
print_star();
|
||||
print_star( );
|
||||
printf("\n");
|
||||
|
||||
// out:
|
||||
|
||||
@@ -5,11 +5,11 @@
|
||||
|
||||
static int i = 10;
|
||||
|
||||
int main()
|
||||
int main( )
|
||||
{
|
||||
printf("[%s]i=%d\n", __FUNCTION__, i);
|
||||
// func();
|
||||
call_func();
|
||||
call_func( );
|
||||
|
||||
exit(0);
|
||||
}
|
||||
@@ -13,5 +13,5 @@ static void func(void)
|
||||
|
||||
void call_func(void)
|
||||
{
|
||||
func();
|
||||
func( );
|
||||
}
|
||||
@@ -5,10 +5,10 @@
|
||||
|
||||
int i = 10;
|
||||
|
||||
int main()
|
||||
int main( )
|
||||
{
|
||||
printf("[%s]i=%d\n", __FUNCTION__, i);
|
||||
func();
|
||||
func( );
|
||||
|
||||
exit(0);
|
||||
}
|
||||
@@ -1,11 +1,11 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#define PI 3.14
|
||||
#define ADD 2 + 3
|
||||
#define PI 3.14
|
||||
#define ADD 2 + 3
|
||||
#define ADD1 (2 + 3)
|
||||
|
||||
#define MAX(a, b) (a > b ? a : b)
|
||||
#define MAX(a, b) (a > b ? a : b)
|
||||
#define MAX1(a, b) ((a) > (b) ? (a) : (b))
|
||||
|
||||
#define MAX2(a, b) \
|
||||
@@ -25,7 +25,7 @@ int max(int a, int b)
|
||||
return a > b ? a : b;
|
||||
}
|
||||
|
||||
int main()
|
||||
int main( )
|
||||
{
|
||||
// printf("%d\n", ADD * ADD);
|
||||
// 相当于 2+3*2+3
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
#include <stdbool.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
int main()
|
||||
int main( )
|
||||
{
|
||||
bool a = false;
|
||||
printf("a = %d\n", a);
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
int main()
|
||||
int main( )
|
||||
{
|
||||
int ch;
|
||||
ch = getchar();
|
||||
ch = getchar( );
|
||||
putchar(ch);
|
||||
|
||||
exit(0);
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
#define STRSIZE 32
|
||||
|
||||
int main()
|
||||
int main( )
|
||||
{
|
||||
char str[STRSIZE];
|
||||
gets(str);
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
|
||||
#define STRSIZE 10
|
||||
|
||||
int main()
|
||||
int main( )
|
||||
{
|
||||
// printf("hello world\n");
|
||||
|
||||
@@ -16,17 +16,16 @@ int main()
|
||||
// printf("%c\n", ch);
|
||||
// out: A
|
||||
|
||||
int i = 255;
|
||||
float f = 123.45678;
|
||||
char str[STRSIZE] = "helloworld";
|
||||
double dou = 123.456;
|
||||
long long l = 123456;
|
||||
int i = 255;
|
||||
float f = 123.45678;
|
||||
char str[STRSIZE] = "helloworld";
|
||||
double dou = 123.456;
|
||||
long long l = 123456;
|
||||
// 不加\n,before while()存入了缓冲区,故不输出
|
||||
// printf("[%s:%d]before while().", __FUNCTION__, __LINE__);
|
||||
printf("[%s:%d]before while().\n", __FUNCTION__, __LINE__);
|
||||
while (1)
|
||||
{
|
||||
}
|
||||
{}
|
||||
// printf("[%s:%d]after while().", __FUNCTION__, __LINE__);
|
||||
printf("[%s:%d]after while().\n", __FUNCTION__, __LINE__);
|
||||
// printf("f = %8.1f\n", f);
|
||||
|
||||
@@ -12,13 +12,13 @@
|
||||
// 但是这时候运行输入hello,不会报错
|
||||
// 实际上是越界了
|
||||
|
||||
int main()
|
||||
int main( )
|
||||
{
|
||||
int i;
|
||||
int i;
|
||||
float f;
|
||||
char str[STRSIZE];
|
||||
int ret;
|
||||
char ch;
|
||||
char str[STRSIZE];
|
||||
int ret;
|
||||
char ch;
|
||||
|
||||
printf("Please enter:\n");
|
||||
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
#include <math.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <math.h>
|
||||
|
||||
#define WEIGHT 3.0e-23
|
||||
#define KQ 950
|
||||
#define KQ 950
|
||||
|
||||
static void water(void)
|
||||
{
|
||||
@@ -69,8 +69,8 @@ void root(void)
|
||||
exit(1);
|
||||
}
|
||||
disc = b * b - 4 * a * c;
|
||||
p = -b / 2 * a;
|
||||
q = sqrt(disc) / 2 * a;
|
||||
p = -b / 2 * a;
|
||||
q = sqrt(disc) / 2 * a;
|
||||
|
||||
x1 = p + q;
|
||||
x2 = p - q;
|
||||
@@ -79,13 +79,13 @@ void root(void)
|
||||
printf("x2 = %f\n", x2);
|
||||
}
|
||||
|
||||
int main()
|
||||
int main( )
|
||||
{
|
||||
// water();
|
||||
|
||||
// area();
|
||||
|
||||
root();
|
||||
root( );
|
||||
|
||||
exit(0);
|
||||
}
|
||||
@@ -11,7 +11,7 @@
|
||||
|
||||
// 闰年的判断:能被4整除但不能被100整除,或者能被400整除
|
||||
|
||||
int main()
|
||||
int main( )
|
||||
{
|
||||
|
||||
int year;
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#define LEFT 1
|
||||
#define LEFT 1
|
||||
#define RIGHT 100
|
||||
|
||||
int main()
|
||||
int main( )
|
||||
{
|
||||
int i;
|
||||
int sum = 0;
|
||||
|
||||
@@ -1,26 +1,20 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
int main()
|
||||
int main( )
|
||||
{
|
||||
int ch;
|
||||
|
||||
ch = getchar();
|
||||
ch = getchar( );
|
||||
|
||||
switch (ch)
|
||||
{
|
||||
case 'a':
|
||||
case 'A':
|
||||
printf("Ant\n");
|
||||
break;
|
||||
case 'A': printf("Ant\n"); break;
|
||||
case 'b':
|
||||
case 'B':
|
||||
printf("Butterfly\n");
|
||||
break;
|
||||
case 'B': printf("Butterfly\n"); break;
|
||||
case 'c':
|
||||
case 'C':
|
||||
printf("Cobra\n");
|
||||
break;
|
||||
case 'C': printf("Cobra\n"); break;
|
||||
default:
|
||||
printf("Input error");
|
||||
// break;
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
// #define N 10
|
||||
#define N 32
|
||||
|
||||
int main()
|
||||
int main( )
|
||||
{
|
||||
|
||||
// char str[N] = {'a', 'b', 'c'};
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
|
||||
#define STR_SIZE 32
|
||||
|
||||
int main()
|
||||
int main( )
|
||||
{
|
||||
char str[32] = "hello\0abc";
|
||||
char str1[STR_SIZE] = "hello";
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
#define M 2
|
||||
#define N 3
|
||||
|
||||
int main()
|
||||
int main( )
|
||||
{
|
||||
|
||||
// int a[M][N] = {{1, 2, 3}, {4, 5, 6}};
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
#define M 3
|
||||
|
||||
int main()
|
||||
int main( )
|
||||
{
|
||||
// int arr[M] = {1};
|
||||
// static int arr[M];
|
||||
|
||||
@@ -22,7 +22,7 @@ static void fibonacci(void)
|
||||
|
||||
while (i < j)
|
||||
{
|
||||
tmp = fib[i];
|
||||
tmp = fib[i];
|
||||
fib[i] = fib[j];
|
||||
fib[j] = tmp;
|
||||
|
||||
@@ -54,8 +54,8 @@ static void sort1(void)
|
||||
{
|
||||
if (a[j] > a[j + 1])
|
||||
{
|
||||
tmp = a[j];
|
||||
a[j] = a[j + 1];
|
||||
tmp = a[j];
|
||||
a[j] = a[j + 1];
|
||||
a[j + 1] = tmp;
|
||||
}
|
||||
}
|
||||
@@ -89,7 +89,7 @@ static void sort2(void)
|
||||
}
|
||||
if (i != k)
|
||||
{
|
||||
tmp = a[i];
|
||||
tmp = a[i];
|
||||
a[i] = a[k];
|
||||
a[k] = tmp;
|
||||
}
|
||||
@@ -116,7 +116,7 @@ static void base_convert(void)
|
||||
do
|
||||
{
|
||||
n[i] = num % base;
|
||||
num = num / base;
|
||||
num = num / base;
|
||||
i++;
|
||||
} while (num != 0);
|
||||
|
||||
@@ -133,7 +133,7 @@ static void base_convert(void)
|
||||
static void primer(void)
|
||||
{
|
||||
char primer[1001] = {0};
|
||||
int i, j;
|
||||
int i, j;
|
||||
|
||||
for (i = 2; i < 1001; i++)
|
||||
{
|
||||
@@ -148,7 +148,7 @@ static void primer(void)
|
||||
}
|
||||
}
|
||||
|
||||
int main()
|
||||
int main( )
|
||||
{
|
||||
// fibonacci();
|
||||
|
||||
@@ -158,7 +158,7 @@ int main()
|
||||
|
||||
// base_convert();
|
||||
|
||||
primer();
|
||||
primer( );
|
||||
|
||||
exit(0);
|
||||
}
|
||||
@@ -6,12 +6,12 @@
|
||||
// a[i]value: a[i] = *(a+i) = *(p+i) = p[i]
|
||||
// &a[i]: &a[i] = a+i = p+i = &p[i]
|
||||
|
||||
int main()
|
||||
int main( )
|
||||
{
|
||||
|
||||
int a[] = {5, 1, 7, 2, 8, 3};
|
||||
int y;
|
||||
int *p = &a[1];
|
||||
int* p = &a[1];
|
||||
|
||||
y = (*--p)++;
|
||||
|
||||
|
||||
@@ -2,10 +2,10 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
int main()
|
||||
int main( )
|
||||
{
|
||||
|
||||
char *str = "hello";
|
||||
char* str = "hello";
|
||||
|
||||
printf("%d %d\n", sizeof(str), strlen(str));
|
||||
// out: 8 5
|
||||
|
||||
@@ -18,12 +18,12 @@
|
||||
|
||||
#define PI 3.14
|
||||
|
||||
int main()
|
||||
int main( )
|
||||
{
|
||||
int i = 1;
|
||||
int j = 100;
|
||||
|
||||
const int *const p = &i;
|
||||
const int* const p = &i;
|
||||
|
||||
//(F) p = &j;
|
||||
|
||||
|
||||
@@ -3,11 +3,11 @@
|
||||
|
||||
|
||||
|
||||
int main()
|
||||
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;
|
||||
|
||||
|
||||
|
||||
@@ -3,16 +3,16 @@
|
||||
|
||||
|
||||
|
||||
int main()
|
||||
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);
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
int main()
|
||||
int main( )
|
||||
{
|
||||
int *p;
|
||||
int* p;
|
||||
|
||||
*p = 1;
|
||||
|
||||
|
||||
@@ -3,12 +3,12 @@
|
||||
#include <string.h>
|
||||
|
||||
|
||||
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;
|
||||
char *tmp;
|
||||
char* tmp;
|
||||
|
||||
for (i = 0; i < 5 - 1; i++)
|
||||
{
|
||||
|
||||
11
C07-函数/arr.c
11
C07-函数/arr.c
@@ -1,20 +1,21 @@
|
||||
#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));
|
||||
// out: 8 指针
|
||||
|
||||
for (i = 0; i < size; i++) printf("%d ", *(p + i));
|
||||
for (i = 0; i < size; i++)
|
||||
printf("%d ", *(p + i));
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
|
||||
void func(int *p, int size)
|
||||
void func(int* p, int size)
|
||||
{
|
||||
int *tmp;
|
||||
int* tmp;
|
||||
|
||||
for (int i = 0; i < size / 2; i++)
|
||||
{
|
||||
@@ -24,7 +25,7 @@ void func(int *p, int size)
|
||||
}
|
||||
}
|
||||
|
||||
int main()
|
||||
int main( )
|
||||
{
|
||||
int a[] = {1, 3, 5, 7, 9};
|
||||
|
||||
|
||||
@@ -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++)
|
||||
@@ -25,7 +25,7 @@ char *mystrncpy(char *dest, const char *src, size_t n)
|
||||
}
|
||||
|
||||
|
||||
int main()
|
||||
int main( )
|
||||
{
|
||||
char str1[] = "helloworld";
|
||||
char str2[128];
|
||||
|
||||
@@ -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,14 +57,14 @@ 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;
|
||||
return *(p + num);
|
||||
}
|
||||
|
||||
int main()
|
||||
int main( )
|
||||
{
|
||||
int i, j;
|
||||
int a[M][N] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12};
|
||||
@@ -76,7 +76,7 @@ int main()
|
||||
|
||||
// find_num(a, 2);
|
||||
|
||||
int *res;
|
||||
int* res;
|
||||
|
||||
res = find_num(a, 2);
|
||||
if (NULL != res)
|
||||
|
||||
@@ -11,7 +11,7 @@ int sub(int a, int b)
|
||||
return a - b;
|
||||
}
|
||||
|
||||
int main()
|
||||
int main( )
|
||||
{
|
||||
int a = 3, b = 5;
|
||||
int ret;
|
||||
|
||||
@@ -11,7 +11,7 @@ void b(void)
|
||||
{
|
||||
printf("[%s]begin!\n", __FUNCTION__);
|
||||
printf("[%s]call c()!\n", __FUNCTION__);
|
||||
c();
|
||||
c( );
|
||||
printf("[%s]c() returned!\n", __FUNCTION__);
|
||||
printf("[%s]end!\n", __FUNCTION__);
|
||||
}
|
||||
@@ -20,16 +20,16 @@ void a(void)
|
||||
{
|
||||
printf("[%s]begin!\n", __FUNCTION__);
|
||||
printf("[%s]call b()!\n", __FUNCTION__);
|
||||
b();
|
||||
b( );
|
||||
printf("[%s]b() returned!\n", __FUNCTION__);
|
||||
printf("[%s]end!\n", __FUNCTION__);
|
||||
}
|
||||
|
||||
int main()
|
||||
int main( )
|
||||
{
|
||||
printf("[%s]begin!\n", __FUNCTION__);
|
||||
printf("[%s]call a()!\n", __FUNCTION__);
|
||||
a();
|
||||
a( );
|
||||
printf("[%s]a() returned!\n", __FUNCTION__);
|
||||
printf("[%s]end!\n", __FUNCTION__);
|
||||
// out:
|
||||
|
||||
@@ -4,9 +4,9 @@
|
||||
void print_hello(void);
|
||||
|
||||
// 主调函数
|
||||
int main()
|
||||
int main( )
|
||||
{
|
||||
print_hello();
|
||||
print_hello( );
|
||||
|
||||
exit(0);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
@@ -9,7 +9,8 @@ int main(int argc, char *argv[])
|
||||
|
||||
// for (int i = 0; i < argc; i++) puts(argv[i]);
|
||||
|
||||
for (int i = 0; argv[i] != NULL; i++) puts(argv[i]);
|
||||
for (int i = 0; argv[i] != NULL; i++)
|
||||
puts(argv[i]);
|
||||
|
||||
// printf("Hello!\n");
|
||||
|
||||
|
||||
@@ -22,7 +22,7 @@ int dist(int a, int b, int c)
|
||||
return max(a, b, c) - min(a, b, c);
|
||||
}
|
||||
|
||||
int main()
|
||||
int main( )
|
||||
{
|
||||
int a = 3, b = 5, c = 10;
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -26,7 +26,7 @@ void swap(int *p, int *q)
|
||||
*p = *q;
|
||||
*q = tmp;
|
||||
}
|
||||
int main()
|
||||
int main( )
|
||||
{
|
||||
int i = 3, j = 5;
|
||||
|
||||
|
||||
@@ -27,7 +27,7 @@ enum
|
||||
// };
|
||||
|
||||
|
||||
int main()
|
||||
int main( )
|
||||
{
|
||||
// enum day a = MON;
|
||||
|
||||
|
||||
@@ -40,18 +40,18 @@ struct student_st
|
||||
};
|
||||
|
||||
|
||||
void func(struct simp_st *b)
|
||||
void func(struct simp_st* b)
|
||||
{
|
||||
printf("%d\n", sizeof(b));
|
||||
}
|
||||
|
||||
int main()
|
||||
int main( )
|
||||
{
|
||||
// TYPE NAME = VALUE;
|
||||
|
||||
|
||||
struct simp_st a;
|
||||
struct simp_st *p = &a;
|
||||
struct simp_st* p = &a;
|
||||
|
||||
// func(a);
|
||||
|
||||
|
||||
@@ -47,7 +47,7 @@ NODEP p; // struct node_st *p;
|
||||
*
|
||||
*/
|
||||
|
||||
int main()
|
||||
int main( )
|
||||
{
|
||||
INT i = 100; // int i;
|
||||
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
int main()
|
||||
int main( )
|
||||
{
|
||||
int *p;
|
||||
int* p;
|
||||
int num = 5;
|
||||
|
||||
p = malloc(sizeof(int) * num);
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
int main()
|
||||
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);
|
||||
|
||||
@@ -21,10 +21,10 @@ void *func(int *p, int n)
|
||||
return p;
|
||||
}
|
||||
|
||||
int main()
|
||||
int main( )
|
||||
{
|
||||
int num = 100;
|
||||
int *p = NULL;
|
||||
int* p = NULL;
|
||||
|
||||
// func(&p, num);
|
||||
|
||||
|
||||
@@ -4,10 +4,10 @@
|
||||
#include "tool1.h"
|
||||
#include "tool2.h"
|
||||
|
||||
int main()
|
||||
int main( )
|
||||
{
|
||||
mytool1();
|
||||
mytool2();
|
||||
mytool1( );
|
||||
mytool2( );
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -16,7 +16,7 @@
|
||||
|
||||
#define NR_BALL 27
|
||||
|
||||
int check(queue *qu)
|
||||
int check(queue* qu)
|
||||
{
|
||||
int i = (qu->head + 1) % MAXSIZE;
|
||||
|
||||
@@ -30,27 +30,27 @@ int check(queue *qu)
|
||||
return 1;
|
||||
}
|
||||
|
||||
int main()
|
||||
int main( )
|
||||
{
|
||||
int i;
|
||||
queue *qu;
|
||||
queue* qu;
|
||||
int t, value;
|
||||
int time;
|
||||
sqstack *st_min, *st_fivemin, *st_hour;
|
||||
|
||||
qu = qu_create();
|
||||
qu = qu_create( );
|
||||
if (NULL == qu)
|
||||
exit(1);
|
||||
|
||||
st_min = st_create();
|
||||
st_min = st_create( );
|
||||
if (NULL == st_min)
|
||||
exit(1);
|
||||
|
||||
st_fivemin = st_create();
|
||||
st_fivemin = st_create( );
|
||||
if (NULL == st_fivemin)
|
||||
exit(1);
|
||||
|
||||
st_hour = st_create();
|
||||
st_hour = st_create( );
|
||||
if (NULL == st_hour)
|
||||
exit(1);
|
||||
|
||||
|
||||
@@ -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_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;
|
||||
|
||||
@@ -85,7 +85,7 @@ static void deal_op(sqstack *snum, sqstack *sop, char op)
|
||||
}
|
||||
|
||||
|
||||
int main()
|
||||
int main( )
|
||||
{
|
||||
int i;
|
||||
char str[] = "(11+3)*2-5";
|
||||
@@ -94,11 +94,11 @@ int main()
|
||||
int flag = 0;
|
||||
int old_op;
|
||||
|
||||
snum = st_create();
|
||||
snum = st_create( );
|
||||
if (NULL == snum)
|
||||
exit(1);
|
||||
|
||||
sop = st_create();
|
||||
sop = st_create( );
|
||||
if (NULL == sop)
|
||||
exit(1);
|
||||
|
||||
|
||||
@@ -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
|
||||
@@ -3,17 +3,17 @@
|
||||
|
||||
#include "sqlist.h"
|
||||
|
||||
int main()
|
||||
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};
|
||||
|
||||
int i, err;
|
||||
|
||||
list = sqlist_create();
|
||||
list = sqlist_create( );
|
||||
// sqlist_create1(&list);
|
||||
if (NULL == list)
|
||||
{
|
||||
@@ -21,7 +21,7 @@ int main()
|
||||
exit(1);
|
||||
}
|
||||
|
||||
list1 = sqlist_create();
|
||||
list1 = sqlist_create( );
|
||||
if (NULL == list1)
|
||||
{
|
||||
fprintf(stderr, "sqlist_create() failed!\n");
|
||||
|
||||
@@ -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)); \
|
||||
#define container_of(ptr, type, member) \
|
||||
({ \
|
||||
const typeof(((type*)0)->member)* __mptr = (ptr); \
|
||||
(type*)((char*)__mptr - offsetof(type, member)); \
|
||||
})
|
||||
|
||||
#define list_entry(ptr, type, member) container_of(ptr, type, member)
|
||||
|
||||
@@ -14,16 +14,16 @@ 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);
|
||||
}
|
||||
|
||||
int main()
|
||||
int main( )
|
||||
{
|
||||
int i;
|
||||
struct score_st *datap;
|
||||
struct list_head *cur;
|
||||
struct score_st* datap;
|
||||
struct list_head* cur;
|
||||
|
||||
LIST_HEAD(head);
|
||||
|
||||
@@ -35,8 +35,8 @@ int main()
|
||||
|
||||
datap->id = i;
|
||||
snprintf(datap->name, NAMESIZE, "stu%d", i);
|
||||
datap->math = rand() % 100;
|
||||
datap->chinese = rand() % 100;
|
||||
datap->math = rand( ) % 100;
|
||||
datap->chinese = rand( ) % 100;
|
||||
|
||||
list_add(&datap->node, &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,33 +14,33 @@ 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);
|
||||
}
|
||||
|
||||
|
||||
int main()
|
||||
int main( )
|
||||
{
|
||||
LLIST *handler;
|
||||
LLIST* handler;
|
||||
int i, ret;
|
||||
struct score_st tmp;
|
||||
|
||||
@@ -52,8 +52,8 @@ int main()
|
||||
{
|
||||
tmp.id = i;
|
||||
snprintf(tmp.name, NAMESIZE, "std%d", i);
|
||||
tmp.math = rand() % 100;
|
||||
tmp.chinese = rand() % 100;
|
||||
tmp.math = rand( ) % 100;
|
||||
tmp.chinese = rand( ) % 100;
|
||||
|
||||
ret = llist_insert(handler, &tmp, LLIST_FORWARD);
|
||||
if (ret)
|
||||
@@ -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,33 +14,33 @@ 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);
|
||||
}
|
||||
|
||||
|
||||
int main()
|
||||
int main( )
|
||||
{
|
||||
LLIST *handler;
|
||||
LLIST* handler;
|
||||
int i, ret;
|
||||
struct score_st tmp;
|
||||
|
||||
@@ -52,8 +52,8 @@ int main()
|
||||
{
|
||||
tmp.id = i;
|
||||
snprintf(tmp.name, NAMESIZE, "std%d", i);
|
||||
tmp.math = rand() % 100;
|
||||
tmp.chinese = rand() % 100;
|
||||
tmp.math = rand( ) % 100;
|
||||
tmp.chinese = rand( ) % 100;
|
||||
|
||||
ret = llist_insert(handler, &tmp, LLIST_FORWARD);
|
||||
if (ret)
|
||||
@@ -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,33 +14,33 @@ 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);
|
||||
}
|
||||
|
||||
|
||||
int main()
|
||||
int main( )
|
||||
{
|
||||
LLIST *handler;
|
||||
LLIST* handler;
|
||||
int i, ret;
|
||||
struct score_st tmp;
|
||||
|
||||
@@ -52,8 +52,8 @@ int main()
|
||||
{
|
||||
tmp.id = i;
|
||||
snprintf(tmp.name, NAMESIZE, "std%d", i);
|
||||
tmp.math = rand() % 100;
|
||||
tmp.chinese = rand() % 100;
|
||||
tmp.math = rand( ) % 100;
|
||||
tmp.chinese = rand( ) % 100;
|
||||
|
||||
ret = handler->insert(handler, &tmp, LLIST_FORWARD);
|
||||
if (ret)
|
||||
|
||||
@@ -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,33 +14,33 @@ 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);
|
||||
}
|
||||
|
||||
|
||||
int main()
|
||||
int main( )
|
||||
{
|
||||
LLIST *handler;
|
||||
LLIST* handler;
|
||||
int i, ret;
|
||||
struct score_st tmp;
|
||||
|
||||
@@ -52,8 +52,8 @@ int main()
|
||||
{
|
||||
tmp.id = i;
|
||||
snprintf(tmp.name, NAMESIZE, "std%d", i);
|
||||
tmp.math = rand() % 100;
|
||||
tmp.chinese = rand() % 100;
|
||||
tmp.math = rand( ) % 100;
|
||||
tmp.chinese = rand( ) % 100;
|
||||
|
||||
ret = llist_insert(handler, &tmp, LLIST_FORWARD);
|
||||
if (ret)
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -5,22 +5,22 @@ typedef int datatype;
|
||||
|
||||
typedef struct node_st
|
||||
{
|
||||
datatype data;
|
||||
struct node_st *next;
|
||||
}list;
|
||||
datatype data;
|
||||
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
|
||||
@@ -3,12 +3,12 @@
|
||||
|
||||
#include "list.h"
|
||||
|
||||
int main()
|
||||
int main( )
|
||||
{
|
||||
list *l;
|
||||
list* l;
|
||||
datatype arr[] = {12, 9, 23, 2, 34, 6, 45};
|
||||
|
||||
l = list_create();
|
||||
l = list_create( );
|
||||
if (NULL == l)
|
||||
exit(1);
|
||||
|
||||
|
||||
@@ -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;
|
||||
@@ -101,9 +101,9 @@ void jose_kill(list **me, int n)
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
int main()
|
||||
int main( )
|
||||
{
|
||||
list *list;
|
||||
list* list;
|
||||
|
||||
list = jose_create(JOSE_NUM);
|
||||
|
||||
|
||||
@@ -3,18 +3,18 @@
|
||||
|
||||
#include "nohead.h"
|
||||
|
||||
int main()
|
||||
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++)
|
||||
{
|
||||
tmp.id = i;
|
||||
snprintf(tmp.name, NAMESIZE, "stu%d", i);
|
||||
tmp.math = rand() % 100;
|
||||
tmp.chinese = rand() % 100;
|
||||
tmp.math = rand( ) % 100;
|
||||
tmp.chinese = rand( ) % 100;
|
||||
|
||||
// list = list_insert(list, &tmp);
|
||||
ret = list_insert(&list, &tmp);
|
||||
@@ -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;
|
||||
|
||||
@@ -89,7 +89,7 @@ void poly_union(list *p1, list *p2)
|
||||
r->next = p;
|
||||
}
|
||||
|
||||
int main()
|
||||
int main( )
|
||||
{
|
||||
int a[][2] = {{5, 0}, {2, 1}, {8, 8}, {3, 16}};
|
||||
int b[][2] = {{6, 1}, {16, 6}, {-8, 8}};
|
||||
|
||||
@@ -3,13 +3,13 @@
|
||||
|
||||
#include "queue.h"
|
||||
|
||||
int main()
|
||||
int main( )
|
||||
{
|
||||
queue *sq;
|
||||
queue* sq;
|
||||
datatype arr[] = {2, 34, 89, 12};
|
||||
int i;
|
||||
|
||||
sq = qu_create();
|
||||
sq = qu_create( );
|
||||
if (NULL == sq)
|
||||
exit(1);
|
||||
|
||||
|
||||
@@ -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_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()
|
||||
int main( )
|
||||
{
|
||||
QUEUE *qu;
|
||||
QUEUE* qu;
|
||||
struct score_st tmp;
|
||||
int i, ret;
|
||||
|
||||
@@ -34,8 +34,8 @@ int main()
|
||||
{
|
||||
tmp.id = i;
|
||||
snprintf(tmp.name, NAMESIZE, "stu%d", i);
|
||||
tmp.math = rand() % 100;
|
||||
tmp.chinese = rand() % 100;
|
||||
tmp.math = rand( ) % 100;
|
||||
tmp.chinese = rand( ) % 100;
|
||||
|
||||
if (0 != queue_en(qu, &tmp))
|
||||
break;
|
||||
|
||||
@@ -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
|
||||
@@ -3,13 +3,13 @@
|
||||
|
||||
#include "sqstack.h"
|
||||
|
||||
int main()
|
||||
int main( )
|
||||
{
|
||||
datatype arr[] = {19, 23, 0, 45, 67};
|
||||
sqstack *st;
|
||||
sqstack* st;
|
||||
int i;
|
||||
|
||||
st = st_create();
|
||||
st = st_create( );
|
||||
if (NULL == st)
|
||||
exit(1);
|
||||
|
||||
|
||||
@@ -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()
|
||||
int main( )
|
||||
{
|
||||
STACK *st;
|
||||
STACK* st;
|
||||
struct score_st tmp;
|
||||
int i, ret;
|
||||
|
||||
@@ -34,8 +34,8 @@ int main()
|
||||
{
|
||||
tmp.id = i;
|
||||
snprintf(tmp.name, NAMESIZE, "stu%d", i);
|
||||
tmp.math = rand() % 100;
|
||||
tmp.chinese = rand() % 100;
|
||||
tmp.math = rand( ) % 100;
|
||||
tmp.chinese = rand( ) % 100;
|
||||
|
||||
if (stack_push(st, &tmp))
|
||||
exit(1);
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -313,7 +313,7 @@ static void travel(struct node_st *root)
|
||||
queue_destroy(qu);
|
||||
}
|
||||
|
||||
int main()
|
||||
int main( )
|
||||
{
|
||||
int arr[] = {1, 2, 3, 7, 6, 5, 9, 8, 4};
|
||||
int i;
|
||||
@@ -323,8 +323,8 @@ int main()
|
||||
{
|
||||
tmp.id = arr[i];
|
||||
snprintf(tmp.name, NAMESIZE, "stu%d", arr[i]);
|
||||
tmp.math = rand() % 100;
|
||||
tmp.chinese = rand() % 100;
|
||||
tmp.math = rand( ) % 100;
|
||||
tmp.chinese = rand( ) % 100;
|
||||
|
||||
/* 小往左,大往右 */
|
||||
insert(&tree, &tmp);
|
||||
|
||||
@@ -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,11 +53,11 @@ 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)
|
||||
{
|
||||
*root = newnode();
|
||||
*root = newnode( );
|
||||
if (NULL == *root)
|
||||
return -1;
|
||||
}
|
||||
@@ -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;
|
||||
@@ -82,13 +82,13 @@ static char *find(struct node_st *root, char *key)
|
||||
return find(root->ch[*key - 'a'], key + 1);
|
||||
}
|
||||
|
||||
int main()
|
||||
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)
|
||||
@@ -94,9 +94,9 @@ static struct node_st *load(const char *path)
|
||||
return root;
|
||||
}
|
||||
|
||||
int main()
|
||||
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;
|
||||
@@ -118,11 +118,11 @@ static int save(struct node_st *root, const char *path)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int main()
|
||||
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 main( )
|
||||
{
|
||||
// 以"\033"开头
|
||||
printf("\033[2J\033[1;1H\033[31;4mhello\n\033[0m");
|
||||
|
||||
@@ -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;
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user