Skip to content

Instantly share code, notes, and snippets.

@Chryus
Last active August 29, 2015 13:57
Show Gist options
  • Save Chryus/9570617 to your computer and use it in GitHub Desktop.
Save Chryus/9570617 to your computer and use it in GitHub Desktop.
class LinkedList
attr_reader :root
def initialize node
@root = node
end
def add x
current = root
new_node = Node.new x
until current.neighbor.nil?
current = current.neighbor
end
current.neighbor = new_node
end
def find x
current = root
until current.content == x
current = current.neighbor
end
end
def delete x
current = root
previous = nil
until current.content == x
previous = current
current = current.neighbor
end
previous.neighbor = current.neighbor
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment