mirror of
https://github.com/krahets/hello-algo.git
synced 2026-11-27 15:02:16 +08:00
feat(ko): add the Korean online edition (#2006)
* feat(ko): add the complete Korean online edition * Use UTF-8 for Python CI output on Windows * Remove print-book promotion from the Korean site * fix(ko): preserve emphasis before Korean particles
This commit is contained in:
42
ko/codes/cpp/utils/list_node.hpp
Normal file
42
ko/codes/cpp/utils/list_node.hpp
Normal file
@@ -0,0 +1,42 @@
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user