Class: Listaa::Lista
- Inherits:
-
Object
- Object
- Listaa::Lista
- Includes:
- Enumerable
- Defined in:
- lib/Lista/Lista.rb
Instance Attribute Summary (collapse)
-
- (Object) First
readonly
Returns the value of attribute First.
-
- (Object) Sz
readonly
Returns the value of attribute Sz.
Instance Method Summary (collapse)
- - (Object) at(i)
- - (Object) each
-
- (Lista) initialize
constructor
A new instance of Lista.
- - (Object) iterarFirst(num)
- - (Object) iterarLast(num)
- - (Object) push_back(objeto)
- - (Object) takeAt(i)
- - (Object) takeFirst
- - (Object) to_apa
- - (Object) to_s
Constructor Details
- (Lista) initialize
Returns a new instance of Lista
8 9 10 11 |
# File 'lib/Lista/Lista.rb', line 8 def initialize @First = nil @Sz = 0 end |
Instance Attribute Details
- (Object) First (readonly)
Returns the value of attribute First
7 8 9 |
# File 'lib/Lista/Lista.rb', line 7 def First @First end |
- (Object) Sz (readonly)
Returns the value of attribute Sz
7 8 9 |
# File 'lib/Lista/Lista.rb', line 7 def Sz @Sz end |
Instance Method Details
- (Object) at(i)
24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/Lista/Lista.rb', line 24 def at(i) @Aux = @First if(i<@Sz) for j in 1..i do @Aux = @Aux.next end @Aux.value else nil end end |
- (Object) each
86 87 88 89 90 91 92 |
# File 'lib/Lista/Lista.rb', line 86 def each aux = @First while aux!=nil yield aux.value aux = aux.next end end |
- (Object) iterarFirst(num)
62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/Lista/Lista.rb', line 62 def iterarFirst(num) if(num<@Sz) aux = @First for i in 0..num-1 do aux = aux.next end aux.value else nil end end |
- (Object) iterarLast(num)
74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/Lista/Lista.rb', line 74 def iterarLast(num) if(num<@Sz) aux = @Last for i in 0..num-1 do aux = aux.prev end aux.value else nil end end |
- (Object) push_back(objeto)
13 14 15 16 17 18 19 20 21 22 |
# File 'lib/Lista/Lista.rb', line 13 def push_back(objeto) if(@Sz==0) @First = Nodo.new(objeto,nil,nil) @Last = @First else @Last.next = Nodo.new(objeto,nil,@Last) @Last = @Last.next end @Sz = @Sz + 1 end |
- (Object) takeAt(i)
36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/Lista/Lista.rb', line 36 def takeAt(i) @Aux = @First if(i<@Sz) for j in 1..i-1 do @Aux = @Aux.next end @Aux2 = @Aux.next @Aux.next = @Aux2.next @Sz = @Sz -1 @Aux2.value else nil end end |
- (Object) takeFirst
51 52 53 54 55 56 57 58 59 60 |
# File 'lib/Lista/Lista.rb', line 51 def takeFirst if(@Sz>=1) @Aux = @First @First = @First.next @Sz = @Sz -1 @Aux.value else nil end end |
- (Object) to_apa
103 104 105 106 107 108 109 110 |
# File 'lib/Lista/Lista.rb', line 103 def to_apa a = [] a = sort { |x,y| x <=> y } f="" a.collect{ |x| f=f+x.to_s+"\n"} f end |
- (Object) to_s
94 95 96 97 98 99 100 101 |
# File 'lib/Lista/Lista.rb', line 94 def to_s a = [] a = sort { |x,y| x <=> y } f="" a.collect{ |x| f=f+x.autorTo_s+"\n"} f end |