repl.it
@anonymous/

PrimeSomeBlock

Ruby

No description

fork
loading
Files
  • main.rb
  • linked_list.rb
  • node.rb
main.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
require_relative "./node"
require_relative "./linked_list"

n4 = Node.new(value: 5)
n3 = Node.new(value: 3, next_node: n4)
n2 = Node.new(value: 7, next_node: n3)
n1 = Node.new(value: 7, next_node: n2)

linked_list1 = LinkedList.new(
  nodes: [n1, n2, n3, n4]
)

puts <<~HEREDOC
  Rotating #{linked_list1.to_s} by 2 places.
    :: #{linked_list1.rotate(2).to_s}
    
HEREDOC

n9 = Node.new(value: 5)
n8 = Node.new(value: 4, next_node: n9)
n7 = Node.new(value: 3, next_node: n8)
n6 = Node.new(value: 2, next_node: n7)
n5 = Node.new(value: 1, next_node: n6)

linked_list2 = LinkedList.new(
  nodes: [n5, n6, n7, n8, n9]
)

puts <<~HEREDOC
  Rotating #{linked_list2.to_s} by 3 places.
    :: #{linked_list2.rotate(3).to_s}
HEREDOC
ruby 2.5.5p157 (2019-03-15 revision 67260) [x86_64-linux]
?