mirror of
https://github.com/krahets/hello-algo.git
synced 2026-07-11 06:56:06 +00:00
refactor: Replace 结点 with 节点 (#452)
* Replace 结点 with 节点 Update the footnotes in the figures * Update mindmap * Reduce the size of the mindmap.png
This commit is contained in:
@@ -10,16 +10,16 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* 链表结点结构体 */
|
||||
/* 链表节点结构体 */
|
||||
struct ListNode {
|
||||
int val; // 结点值
|
||||
struct ListNode *next; // 指向下一结点的指针(引用)
|
||||
int val; // 节点值
|
||||
struct ListNode *next; // 指向下一节点的指针(引用)
|
||||
};
|
||||
|
||||
// typedef 作用是为一种数据类型定义一个新名字
|
||||
typedef struct ListNode ListNode;
|
||||
|
||||
/* 构造函数,初始化一个新结点 */
|
||||
/* 构造函数,初始化一个新节点 */
|
||||
ListNode *newListNode(int val) {
|
||||
ListNode *node, *next;
|
||||
node = (ListNode *) malloc(sizeof(ListNode));
|
||||
|
||||
@@ -52,18 +52,18 @@ TreeNode *arrToTree(const int *arr, size_t size) {
|
||||
TreeNode *root, *node;
|
||||
TreeNode **queue;
|
||||
|
||||
/* 根结点 */
|
||||
/* 根节点 */
|
||||
root = newTreeNode(arr[0]);
|
||||
/* 辅助队列 */
|
||||
queue = (TreeNode **) malloc(sizeof(TreeNode) * MAX_NODE_SIZE);
|
||||
// 队列指针
|
||||
front = 0, rear = 0;
|
||||
// 将根结点放入队尾
|
||||
// 将根节点放入队尾
|
||||
queue[rear++] = root;
|
||||
// 记录遍历数组的索引
|
||||
index = 0;
|
||||
while (front < rear) {
|
||||
// 取队列中的头结点,并让头结点出队
|
||||
// 取队列中的头节点,并让头节点出队
|
||||
node = queue[front++];
|
||||
index++;
|
||||
if (index < size) {
|
||||
@@ -103,14 +103,14 @@ int *treeToArr(TreeNode *root) {
|
||||
queue = (TreeNode **) malloc(sizeof(TreeNode) * MAX_NODE_SIZE);
|
||||
// 队列指针
|
||||
front = 0, rear = 0;
|
||||
// 将根结点放入队尾
|
||||
// 将根节点放入队尾
|
||||
queue[rear++] = root;
|
||||
/* 辅助数组 */
|
||||
arr = (int *) malloc(sizeof(int) * MAX_NODE_SIZE);
|
||||
// 数组指针
|
||||
index = 0;
|
||||
while (front < rear) {
|
||||
// 取队列中的头结点,并让头结点出队
|
||||
// 取队列中的头节点,并让头节点出队
|
||||
node = queue[front++];
|
||||
if (node != NULL) {
|
||||
arr[index] = node->val;
|
||||
|
||||
Reference in New Issue
Block a user