Class: TreeMap::NodeIterator
- Inherits:
-
Object
- Object
- TreeMap::NodeIterator
show all
- Defined in:
- lib/tree_map/tree_map.rb
Overview
in-order traversal of nodes in tree
Instance Method Summary
collapse
Constructor Details
#initialize(next_node) ⇒ NodeIterator
Returns a new instance of NodeIterator.
625
626
627
628
|
# File 'lib/tree_map/tree_map.rb', line 625
def initialize(next_node)
@next_node = next_node
@last_node = nil
end
|
Instance Method Details
#has_next? ⇒ Boolean
630
631
632
|
# File 'lib/tree_map/tree_map.rb', line 630
def has_next?
!!@next_node
end
|
#step_backward ⇒ Object
642
643
644
645
646
647
648
|
# File 'lib/tree_map/tree_map.rb', line 642
def step_backward
if @next_node
@last_node = @next_node
@next_node = @next_node.prev_node
@last_node
end
end
|
#step_forward ⇒ Object
634
635
636
637
638
639
640
|
# File 'lib/tree_map/tree_map.rb', line 634
def step_forward
if @next_node
@last_node = @next_node
@next_node = @next_node.next_node
@last_node
end
end
|