Class: List

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/exam1/linkedlist.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(head) ⇒ List

Returns a new instance of List.



21
22
23
24
25
26
27
28
# File 'lib/exam1/linkedlist.rb', line 21

def initialize(head)


   @head = head
   @tail = head
    
    
end

Instance Attribute Details

#headObject

Returns the value of attribute head.



17
18
19
# File 'lib/exam1/linkedlist.rb', line 17

def head
  @head
end

#tailObject

Returns the value of attribute tail.



17
18
19
# File 'lib/exam1/linkedlist.rb', line 17

def tail
  @tail
end

Instance Method Details

#eachObject



87
88
89
90
91
92
93
94
95
96
# File 'lib/exam1/linkedlist.rb', line 87

def each

   actual = @tail

  while actual != nil
     yield actual.value
     actual = actual.siguiente
  end

end

#insert_head(nodo) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
# File 'lib/exam1/linkedlist.rb', line 30

def insert_head(nodo)

  
  aux = @head
  
  @head.siguiente = nodo
  @head = @head.siguiente
  @head.previo = aux
  
  
end

#insert_tail(nodo) ⇒ Object



42
43
44
45
46
47
48
49
# File 'lib/exam1/linkedlist.rb', line 42

def insert_tail(nodo)
  
  aux = @tail
  @tail = nodo
  aux.previo = @tail
  @tail.siguiente = aux

end


63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/exam1/linkedlist.rb', line 63

def print

  actual = @tail
  
  while actual != nil
  
    "#{actual.value}"
    actual = actual.siguiente
  
  end
  
end

#remove_headObject



51
52
53
54
55
56
57
58
59
60
# File 'lib/exam1/linkedlist.rb', line 51

def remove_head

  aux = @head
  @head = @head.previo
  return aux.value
  #puts @head.value
  
    
  
end

#remove_tailObject



76
77
78
79
80
81
82
83
84
85
# File 'lib/exam1/linkedlist.rb', line 76

def remove_tail

  actual = @tail
  if @tail.siguiente != nil
  @tail = @tail.siguiente
  end
  return actual.value


end