Last active
August 29, 2015 13:57
-
-
Save Chryus/9570617 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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