mirror of
https://github.com/krahets/hello-algo.git
synced 2026-11-24 23:50:45 +08:00
Batch 3a of the runnable-snippets plan. heap_operations now cites the heap demos in Python, C++, Java, C#, Go, Swift, Rust and Kotlin; the demos call the library directly instead of push/pop helpers and print each popped value. list_node_class cites each language's shared ListNode (Swift stays literal) and doubly_list_node_class cites linkedlist_deque (Go stays literal). Node comments adopt reviewed source wording, Rust and Swift get import regions, the Ruby typo 前躯 becomes 前驱, and the TypeScript doubly node fields become nullable. en, ja, ko and zh-hant are regenerated; ru is synced by hand. Co-Authored-By: Claude Opus 5.5 <[email protected]>
34 lines
748 B
JavaScript
34 lines
748 B
JavaScript
/**
|
|
* File: ListNode.js
|
|
* Created Time: 2022-12-12
|
|
* Author: IsChristina ([email protected])
|
|
*/
|
|
|
|
// [region]{list_node}
|
|
/* 연결 리스트 노드 */
|
|
class ListNode {
|
|
val; // 노드 값
|
|
next; // 다음 노드를 가리키는 참조(포인터)
|
|
constructor(val, next) {
|
|
this.val = val === undefined ? 0 : val;
|
|
this.next = next === undefined ? null : next;
|
|
}
|
|
}
|
|
// [endregion]{list_node}
|
|
|
|
/* 리스트를 연결 리스트로 역직렬화 */
|
|
function arrToLinkedList(arr) {
|
|
const dum = new ListNode(0);
|
|
let head = dum;
|
|
for (const val of arr) {
|
|
head.next = new ListNode(val);
|
|
head = head.next;
|
|
}
|
|
return dum.next;
|
|
}
|
|
|
|
module.exports = {
|
|
ListNode,
|
|
arrToLinkedList,
|
|
};
|