summaryrefslogtreecommitdiff
path: root/lib/data_structures
diff options
context:
space:
mode:
authormo khan <mo@mokhan.ca>2013-07-11 13:30:25 -0600
committermo khan <mo@mokhan.ca>2013-07-11 13:30:25 -0600
commitfa2bc824f1e892c579847c8db2a7057da4c52ef2 (patch)
treea1a95daf598de610f20088a5aa8a1fcfb78545ed /lib/data_structures
parentc63531f0c68ca214c810fc77be647d3b142895f0 (diff)
remove null node
Diffstat (limited to 'lib/data_structures')
-rw-r--r--lib/data_structures/linked_list_stack.rb25
1 files changed, 6 insertions, 19 deletions
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