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
32 changes: 29 additions & 3 deletions array-list.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,53 @@

class ArrayList
def initialize
@storage = []
@storage = [0,0,0,0,0]
@size = 0
end

def add(value)
@storage[@size] = value
@size += 1
end

def delete(value)
def delete
return nil if empty?
@size -= 1
end

def display
@size.times do |i|
puts @storage[i]
end
end

def include?(key)
@size.times do |i|
if @storage[i] == key
return true
end
end
return false
end

def size
return @size
end

def max
return nil if empty?
biggest = 0
@size.times do |i|
if @storage[i] > @storage[biggest]
biggest = i
end
end
return @storage[biggest]
end

def empty?
@size == 0
end
end

# Initializing an Array List
Expand All @@ -37,5 +63,5 @@ def max
arr.display

puts "Delete 10 and then display the array list:"
arr.delete(10)
arr.delete
arr.display
17 changes: 15 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=nill)
@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,9 +63,22 @@ def display
end

def include?(key)
current = @head
while current != nil
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.

👍


def size
current = @head
@size = 0
while current != nil
@size += 1
current = current.next_node
end
return @size
end

Choose a reason for hiding this comment

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

👍


def max
Expand Down