Created
June 6, 2021 13:47
-
-
Save edipofederle/bc935c7af3294cb1b740cdec87627b8c to your computer and use it in GitHub Desktop.
This file contains 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
require 'set' | |
class LinkedList | |
include Enumerable | |
def initialize(head, tail = nil) | |
@head, @tail = head, tail | |
end | |
def <<(item) | |
LinkedList.new(item, self) | |
end | |
def inspect | |
[@head, @tail].inspect | |
end | |
def each(&block) | |
block.call(@head) | |
@tail.each(&block) if @tail | |
end | |
end | |
list = LinkedList.new(73) << 12 << 42 | |
puts list | |
s = Set.new(list) | |
puts s.size |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment