2014-06-25 15:00:24 +02:00
|
|
|
class List
|
|
|
|
|
|
|
|
def initialize
|
|
|
|
@next = nil
|
|
|
|
end
|
|
|
|
def empty?
|
|
|
|
@next.nil?
|
|
|
|
end
|
|
|
|
|
|
|
|
def get(key)
|
2014-06-25 15:03:39 +02:00
|
|
|
@next ? @next.get(key) : nil
|
2014-06-25 15:00:24 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
def set(key , value)
|
2014-06-25 15:03:39 +02:00
|
|
|
@next ? @next.set(key,value) : @next = Node.new(key,value)
|
2014-06-25 15:00:24 +02:00
|
|
|
value
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
class Node < List
|
|
|
|
def initialize(key,value)
|
|
|
|
@key = key
|
|
|
|
@value = value
|
|
|
|
end
|
|
|
|
def get(key)
|
2014-06-25 15:03:39 +02:00
|
|
|
@key == key ? @value : super(key)
|
2014-06-25 15:00:24 +02:00
|
|
|
end
|
|
|
|
def set(key,value)
|
2014-06-25 15:03:39 +02:00
|
|
|
@key == key ? @value = value : super(key,value)
|
2014-06-25 15:00:24 +02:00
|
|
|
end
|
|
|
|
end
|
2014-08-13 10:59:51 +02:00
|
|
|
|
|
|
|
# https://www.youtube.com/watch?v=HJ-719EGIts
|