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

@@ -12,13 +12,10 @@ extern "C" {
#endif
/* 链表节点结构体 */
struct ListNode {
typedef struct ListNode {
int val; // 节点值
struct ListNode *next; // 指向下一节点的引用
};
// typedef 作用是为一种数据类型定义一个新名字
typedef struct ListNode ListNode;
} ListNode;
/* 构造函数,初始化一个新节点 */
ListNode *newListNode(int val) {
@@ -56,4 +53,4 @@ ListNode *getListNode(ListNode *head, int val) {
}
#endif
#endif // LIST_NODE_H
#endif // LIST_NODE_H

View File

@@ -72,12 +72,10 @@ static void printLinkedList(ListNode *node) {
printf("%d\n", node->val);
}
struct Trunk {
typedef struct Trunk {
struct Trunk *prev;
char *str;
};
typedef struct Trunk Trunk;
} Trunk;
Trunk *newTrunk(Trunk *prev, char *str) {
Trunk *trunk = (Trunk *)malloc(sizeof(Trunk));

View File

@@ -16,14 +16,12 @@ extern "C" {
#define MAX_NODE_SIZE 5000
/* 二叉树节点结构体 */
struct TreeNode {
typedef struct TreeNode {
int val; // 节点值
int height; // 节点高度
struct TreeNode *left; // 左子节点指针
struct TreeNode *right; // 右子节点指针
};
typedef struct TreeNode TreeNode;
} TreeNode;
TreeNode *newTreeNode(int val) {
TreeNode *node;