Created
May 22, 2012 06:53
Revisions
-
kronos revised this gist
May 22, 2012 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -21,7 +21,7 @@ def initialize(ary = nil) @head = Node.new(nil) # head element @last = @head if ary ary.each {|value| add(value)} end self end -
kronos renamed this gist
May 22, 2012 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
kronos created this gist
May 22, 2012 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,53 @@ class LinkedList include Enumerable attr_reader :head class Node attr_reader :value attr_accessor :next def initialize(value, _next = nil) @value = value @next = _next end def inspect value.inspect end end def initialize(ary = nil) @head = Node.new(nil) # head element @last = @head if ary ary.each {|value| add(v)} end self end def insert_after(where, value) value = Node.new(value, where.next) where.next = value @last = value if where == @last value end def each p = @head.next while p yield p.value p = p.next end self end def add(value) insert_after(@last, value) end def inspect to_a.inspect end end