diff --git a/array-list.rb b/array-list.rb index a0d0342..8ceb5cb 100644 --- a/array-list.rb +++ b/array-list.rb @@ -2,25 +2,44 @@ class ArrayList def initialize - @storage = [] + @storage = [nil, nil, nil, nil, nil] + @size = 0 end def add(value) + @storage[@size] = value + @storage += 1 end def delete(value) + @size -= 1 end def display + return @storage[0, @size] end def include?(key) + @size.times do |i| + if @storage[i] == key + return true + end + end + return false end def size + @size end def max + biggest = 0 + @size.times do |i| + if @storage[i] > biggest + biggest = i + end + end + end end diff --git a/linked-list.rb b/linked-list.rb index a1b30bd..ad0a484 100644 --- a/linked-list.rb +++ b/linked-list.rb @@ -5,9 +5,9 @@ class Node attr_accessor :value, :next_node - def initialize(val,next_in_line=null) + def initialize(val,next_in_line = nil) @value = val - @next_nodex = next_in_line + @next_node = next_in_line puts "Initialized a Node with value: " + value.to_s end end @@ -63,12 +63,36 @@ def display end def include?(key) + current = @head + full_list = [] + while current.next_node != nil + full_list += [current.value.to_s] + (return true) if current.value == key + current = current.next_node + end + return false end def size + current = @head + count = 1 + full_list = [] + while current.next_node != nil + full_list += [current.value.to_s] #not necessary but nice + current = current.next_node + count += 1 + end + return count end def max + current = @head + max = 0 + while current.next_node != nil + (max += current.value) if current.value > max + current = current.next_node + end + return max end end