Simplify struct declarations of C.

Use PascalCase for all structs in C.
SImplify n_queens.c
Format C code for chapter of graph.
This commit is contained in:
krahets
2023-10-18 02:16:26 +08:00
parent 070d23ee6e
commit 1e49574332
35 changed files with 503 additions and 599 deletions

View File

@ -31,13 +31,11 @@ void constant(int n) {
}
/* 哈希表 */
struct hashTable {
typedef struct {
int key;
int val;
UT_hash_handle hh; // 基于 uthash.h 实现
};
typedef struct hashTable hashTable;
} HashTable;
/* 线性阶 */
void linear(int n) {
@ -57,16 +55,16 @@ void linear(int n) {
free(nodes);
// 长度为 n 的哈希表占用 O(n) 空间
hashTable *h = NULL;
HashTable *h = NULL;
for (int i = 0; i < n; i++) {
hashTable *tmp = malloc(sizeof(hashTable));
HashTable *tmp = malloc(sizeof(HashTable));
tmp->key = i;
tmp->val = i;
HASH_ADD_INT(h, key, tmp);
}
// 内存释放
hashTable *curr, *tmp;
HashTable *curr, *tmp;
HASH_ITER(hh, h, curr, tmp) {
HASH_DEL(h, curr);
free(curr);