KillerDesigner
12/2/2013 - 6:13 PM

linkList.rb

class Node
    attr_accessor :data, :next

    def initialize(data=nil)
        @data = data
    end
end

# Without arbitrary args
class List
    attr_accessor :head, :tail
    attr_reader :count

    def initialize
        @head = Node.new
        @tail = @head.next
        @count = 0
    end

    def insertFirst(val)
        new_node = Node.new(@head)
        new_node.next = @tail
        @head = val
        @tail = new_node
        @count += 1
    end
end