Files
hello-algo/ja/codes/go/pkg/list_node.go
Yudong Jin 7257641e0e Retranslate the complete Japanese online edition from Chinese (#2008)
* Retranslate the complete Japanese online edition from Chinese

* Fit Japanese homepage labels and localize heading permalinks

* Point Japanese contribution instructions to the Japanese preview

* Replace locale conditionals with multilingual UI tables
2026-10-30 02:12:26 +08:00

32 lines
673 B
Go

// File: list_node.go
// Created Time: 2022-11-25
// Author: Reanon (793584285@qq.com)
package pkg
// ListNode は連結リストのノード
type ListNode struct {
Next *ListNode
Val int
}
// NewListNode は連結リストのノードのコンストラクタ
func NewListNode(v int) *ListNode {
return &ListNode{
Next: nil,
Val: v,
}
}
// ArrayToLinkedList は配列をデシリアライズして連結リストにする
func ArrayToLinkedList(arr []int) *ListNode {
// 連結リストのダミーの先頭ノード
dummy := NewListNode(0)
node := dummy
for _, val := range arr {
node.Next = NewListNode(val)
node = node.Next
}
return dummy.Next
}