mirror of
https://github.com/krahets/hello-algo.git
synced 2025-11-01 03:24:24 +08:00
* docs: add Japanese documents (`ja/docs`) * docs: add Japanese documents (`ja/codes`) * docs: add Japanese documents * Remove pythontutor blocks in ja/ * Add an empty at the end of each markdown file. * Add the missing figures (use the English version temporarily). * Add index.md for Japanese version. * Add index.html for Japanese version. * Add missing index.assets * Fix backtracking_algorithm.md for Japanese version. * Add avatar_eltociear.jpg. Fix image links on the Japanese landing page. * Add the Japanese banner. --------- Co-authored-by: krahets <krahets@163.com>
42 lines
860 B
C++
42 lines
860 B
C++
/**
|
|
* File: list_node.hpp
|
|
* Created Time: 2021-12-19
|
|
* Author: krahets (krahets@163.com)
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <iostream>
|
|
#include <vector>
|
|
|
|
using namespace std;
|
|
|
|
/* 連結リストノード */
|
|
struct ListNode {
|
|
int val;
|
|
ListNode *next;
|
|
ListNode(int x) : val(x), next(nullptr) {
|
|
}
|
|
};
|
|
|
|
/* 配列を連結リストに逆シリアル化する */
|
|
ListNode *vecToLinkedList(vector<int> list) {
|
|
ListNode *dum = new ListNode(0);
|
|
ListNode *head = dum;
|
|
for (int val : list) {
|
|
head->next = new ListNode(val);
|
|
head = head->next;
|
|
}
|
|
return dum->next;
|
|
}
|
|
|
|
/* 連結リストに割り当てられたメモリを解放する */
|
|
void freeMemoryLinkedList(ListNode *cur) {
|
|
// メモリを解放
|
|
ListNode *pre;
|
|
while (cur != nullptr) {
|
|
pre = cur;
|
|
cur = cur->next;
|
|
delete pre;
|
|
}
|
|
} |