Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion array-list.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
28 changes: 26 additions & 2 deletions linked-list.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good -- however you don't need full_list in this method at all. so just remove lines 67 and 69


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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍


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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not exactly sure what this method is doing, but it's not doing what I intended, which is to return the largest single value in the linked list.


end
Expand Down