Class: DS::CyclicList
Overview
Class represent list with cycle.
Direct Known Subclasses
Instance Attribute Summary
Attributes inherited from List
Instance Method Summary collapse
-
#cycle_size ⇒ Object
Returns cycle size.
Methods inherited from List
#append, #each, #each_with_index, #empty?, #first, from_array, #initialize, #insert_after, #insert_before, #joint, #last, #length, #looped?, #merge, #orderize, #prepend, #print, #remove, #remove!, #reverse!, #shift, #to_a, #zip?
Constructor Details
This class inherits a constructor from DS::List
Instance Method Details
#cycle_size ⇒ Object
Returns cycle size. If list has no cycles returns 0.
7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/ds/lists/cyclic_list.rb', line 7 def cycle_size counter = 0 if start = self.joint counter = 1 elem = joint.next while elem != start elem = elem.next counter += 1 end end counter end |