mirror of
https://github.com/krahets/hello-algo.git
synced 2026-08-19 15:00:58 +00:00
Add ru version (#1865)
* 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
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
=begin
|
||||
File: list_node.rb
|
||||
Created Time: 2024-03-18
|
||||
Author: Xuan Khoa Tu Nguyen (ngxktuzkai2000@gmail.com)
|
||||
=end
|
||||
|
||||
# ## Класс узла связного списка ###
|
||||
class ListNode
|
||||
attr_accessor :val # Значение узла
|
||||
attr_accessor :next # Ссылка на следующий узел
|
||||
|
||||
def initialize(val=0, next_node=nil)
|
||||
@val = val
|
||||
@next = next_node
|
||||
end
|
||||
end
|
||||
|
||||
# ## Десериализация списка в связный список ###
|
||||
def arr_to_linked_list(arr)
|
||||
head = current = ListNode.new(arr[0])
|
||||
|
||||
for i in 1...arr.length
|
||||
current.next = ListNode.new(arr[i])
|
||||
current = current.next
|
||||
end
|
||||
|
||||
head
|
||||
end
|
||||
|
||||
# ## Сериализация связного списка в список ###
|
||||
def linked_list_to_arr(head)
|
||||
arr = []
|
||||
|
||||
while head
|
||||
arr << head.val
|
||||
head = head.next
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user