From fa2bc824f1e892c579847c8db2a7057da4c52ef2 Mon Sep 17 00:00:00 2001 From: mo khan Date: Thu, 11 Jul 2013 13:30:25 -0600 Subject: remove null node --- lib/data_structures/linked_list_stack.rb | 25 ++++++------------------- 1 file changed, 6 insertions(+), 19 deletions(-) (limited to 'lib/data_structures') diff --git a/lib/data_structures/linked_list_stack.rb b/lib/data_structures/linked_list_stack.rb index 1ed47ba..f83006a 100644 --- a/lib/data_structures/linked_list_stack.rb +++ b/lib/data_structures/linked_list_stack.rb @@ -1,6 +1,6 @@ class LinkedListStack def initialize - @head = NullNode.new + @head = Node.new(nil) end def push(item) @@ -10,6 +10,10 @@ class LinkedListStack def pop @head.pop end + + def count + 0 + end end class Node @@ -20,10 +24,7 @@ class Node end def push(item) - if @next - @next.push(item) - end - + @next.push(item) if @next @next = Node.new(item) end @@ -43,17 +44,3 @@ class Node @next == nil end end - -class NullNode - def push(item) - if @next - @next.push(item) - else - @next = Node.new(item) - end - end - - def pop - return @next.pop if @next - end -end -- cgit v1.2.3