mirror of
https://github.com/krahets/hello-algo.git
synced 2026-07-14 08:06:06 +00:00
Re-translate the Japanese version (#1871)
* Retranslate Japanese docs with GPT-5.4 * Retranslate Japanese code with GPT-5.4
This commit is contained in:
@@ -0,0 +1,59 @@
|
||||
/**
|
||||
* File: list_node.h
|
||||
* Created Time: 2023-01-09
|
||||
* Author: Reanon (793584285@qq.com)
|
||||
*/
|
||||
|
||||
#ifndef LIST_NODE_H
|
||||
#define LIST_NODE_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* 連結リストノード構造体 */
|
||||
typedef struct ListNode {
|
||||
int val; // ノード値
|
||||
struct ListNode *next; // 次のノードへの参照
|
||||
} ListNode;
|
||||
|
||||
/* コンストラクタ。新しいノードを初期化する */
|
||||
ListNode *newListNode(int val) {
|
||||
ListNode *node;
|
||||
node = (ListNode *)malloc(sizeof(ListNode));
|
||||
node->val = val;
|
||||
node->next = NULL;
|
||||
return node;
|
||||
}
|
||||
|
||||
/* 配列をデシリアライズして連結リストに変換する */
|
||||
ListNode *arrToLinkedList(const int *arr, size_t size) {
|
||||
if (size <= 0) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ListNode *dummy = newListNode(0);
|
||||
ListNode *node = dummy;
|
||||
for (int i = 0; i < size; i++) {
|
||||
node->next = newListNode(arr[i]);
|
||||
node = node->next;
|
||||
}
|
||||
return dummy->next;
|
||||
}
|
||||
|
||||
/* 連結リストに割り当てたメモリを解放する */
|
||||
void freeMemoryLinkedList(ListNode *cur) {
|
||||
// メモリを解放する
|
||||
ListNode *pre;
|
||||
while (cur != NULL) {
|
||||
pre = cur;
|
||||
cur = cur->next;
|
||||
free(pre);
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // LIST_NODE_H
|
||||
Reference in New Issue
Block a user