Надо написать что-то типа DoubleLinkedList. Пишу
class DoubleLinkedList
attr_accessor :head
# add TO THE END
def append(new_link)
if @head == nil
@head = new_link
return
end
current = @head
while current.next_link != nil
current = current.next_link
end
current.next_link = new_link
new_link.prev_link = current
end
# print links since tail
def print_links_at_tail(link = nil)
if link == nil
link = @head
print_links_at_tail(link)
end
print_links_at_tail(link.next_link) if link.next_link != nil
puts link.value
end
end
class Link
attr_accessor :value, :next_link, :prev_link
def initialize(value)
@value = value
end
end
struct = DoubleLinkedList.new
link_1 = Link.new('R')
link_2 = Link.new('a')
link_3 = Link.new('i')
link_4 = Link.new('l')
link_5 = Link.new('s')
struct.append(link_1)
struct.append(link_2)
struct.append(link_3)
struct.append(link_4)
struct.append(link_5)
struct.print_links_at_tail
По идее что должно быть распечатано - sliaR. НО! Распечатано - sliaRsliaR. Почему?