first commit

This commit is contained in:
2024-09-08 14:39:20 +08:00
commit a1127e008f
34 changed files with 1403 additions and 0 deletions

58
include/leetcode/utils.h Normal file
View File

@@ -0,0 +1,58 @@
#ifndef UTILS_H
#define UTILS_H
#include <stdio.h>
#include <stdlib.h>
#ifndef FREE
#define FREE(p) \
do \
{ \
free(p); \
p = NULL; \
} while (0)
#endif
#ifndef MALLOC
#define MALLOC(p, s, err) \
do \
{ \
p = malloc(s); \
if (p == NULL) \
goto err; \
} while (0)
#endif
#ifndef REALLOC
#define REALLOC(p, s, err) \
do \
{ \
p = realloc(p, s); \
if (p == NULL) \
goto err; \
}
#endif
#ifndef CALLOC
#define CALLOC(p, s, err) \
do \
{ \
p = calloc(s, 1); \
if (p == NULL) \
goto err; \
} while (0)
#endif
#ifndef ASSERT
#define ASSERT(cond, except, err) \
do \
{ \
if (cond != except) \
{ \
printf("assert failed! at line: %d in %s\n", __LINE__, __FUNCTION__); \
goto err; \
} \
} while (0)
#endif
#endif // UTILS_H