mirror of
https://github.com/krahets/hello-algo.git
synced 2026-06-10 14:25:40 +08:00
* Add Russian docs site baseline * Add Russian localized codebase * Polish Russian code wording * Update ru code translation. * Update code translation and chapter covers. * Fix pythontutor extraction. * Add README and landing page. * placeholder of profiles * Use figures of English version * Remove chapter paperbook
32 lines
679 B
Go
32 lines
679 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 header of linked list
|
|
dummy := NewListNode(0)
|
|
node := dummy
|
|
for _, val := range arr {
|
|
node.Next = NewListNode(val)
|
|
node = node.Next
|
|
}
|
|
return dummy.Next
|
|
}
|