Binary Search Tree, recursive structure

I have below code:

class Node
attr_accessor :val, :left, :right

def initialize(val, l , r )
@val = val
@left = l
@right = r
end

end

morse = Node.new(nil,
Node.new (‘E’,
Node.new (‘I’,
Node.new (‘S’,
Node.new (‘H’, 5 , 4),
Node.new (‘V’, nil, 3)
),
Node.new (‘U’,
Node.new (‘F’, nil, ‘Ę’),
Node.new (18, nil, 2)
)
),
Node.new (‘A’,
Node.new (‘R’,
Node.new (‘L’, nil, ‘Ł’),
Node.new (‘Ą’, nil, nil)
),
Node.new (‘W’,
Node.new (‘P’, nil, nil),
Node.new (‘J’, 1, nil)
)
)
)
,
Node.new (‘T’,
Node.new (‘N’,
Node.new (‘D’,
Node.new (‘B’, 6 , nil),
Node.new (‘X’, nil, nil)
),
Node.new (‘K’,
Node.new (‘C’, ‘Ć’, nil),
Node.new (‘Y’, nil, nil)
)
),
Node.new (‘M’,
Node.new (‘G’,
Node.new (‘Z’, ‘Ż’, nil),
Node.new (‘Q’, ‘Ń’, nil)
),
Node.new (‘O’,
Node.new (‘Ó’, 8, nil),
Node.new (‘H’, 9, 0)
)
)
)
)

Interpreter told me :

``````                  ^
``````

[email protected]:~/ruby> ruby 2.rb
2.rb:15: syntax error, unexpected ‘,’, expecting ‘)’
,Node.new (‘E’,
^
2.rb:15: syntax error, unexpected ‘,’, expecting ‘)’
2.rb:16: syntax error, unexpected ‘,’, expecting ‘)’
Node.new (‘I’,
^
2.rb:17: syntax error, unexpected ‘,’, expecting ‘)’
Node.new (‘S’,
^
2.rb:18: syntax error, unexpected ‘,’, expecting ‘)’
Node.new (‘H’, 5 , 4),
^

I don’t know, what I do wrong.

On Fri, Aug 23, 2013 at 2:34 PM, Wojciech S. [email protected]
wrote:

I have below code:

I don’t know, what I do wrong.

You have spaces between method name “new” and the opening brackets.
These
must go away because otherwise the argument list continues after the
closing bracket.

Kind regards

robert

I did the same mistake again. Thank you!