Skip to content

Instantly share code, notes, and snippets.

@edipofederle
Created June 6, 2021 13:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save edipofederle/bc935c7af3294cb1b740cdec87627b8c to your computer and use it in GitHub Desktop.
Save edipofederle/bc935c7af3294cb1b740cdec87627b8c to your computer and use it in GitHub Desktop.
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