Ruby Logo

Ruby: Linked list node class

class Node ⏎
	attr_accessor :data, :next

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

class LinkedList
	def initialize
		@head = nil
	end

	def append(data)
		new_node = Node.new(data)
		if @head.nil?
			@head = new_node
		else
			current = @head
			while current.next
				current = current.next
			end
			current.next = new_node
		end
	end
end
Accuracy
100 %
0 Mistakes
CPM
0
Average: 0 CPM
Time
0.000 s
Personal best: 80.974 s