Class: Dll

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/tdd/dll_etiqueta.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeDll

Returns a new instance of Dll.



7
8
9
10
# File 'lib/tdd/dll_etiqueta.rb', line 7

def initialize
    @head = nil
    @tail = nil
end

Instance Attribute Details

#headObject

Returns the value of attribute head.



5
6
7
# File 'lib/tdd/dll_etiqueta.rb', line 5

def head
  @head
end

#tailObject

Returns the value of attribute tail.



5
6
7
# File 'lib/tdd/dll_etiqueta.rb', line 5

def tail
  @tail
end

Instance Method Details

#eachObject



67
68
69
70
71
72
73
74
75
76
# File 'lib/tdd/dll_etiqueta.rb', line 67

def each 
   
   it = @head
   
   while it !=nil 
        yield it.value
        it=it.next
   end
    
end

#empty?Boolean

Returns:

  • (Boolean)


53
54
55
56
# File 'lib/tdd/dll_etiqueta.rb', line 53

def empty?
    @head == nil
    @tail == nil
end

#get_headObject



41
42
43
44
45
# File 'lib/tdd/dll_etiqueta.rb', line 41

def get_head
    dummy = @head
    @head = @head.next
    dummy
end

#get_tailObject



47
48
49
50
51
# File 'lib/tdd/dll_etiqueta.rb', line 47

def get_tail
   dummy = @tail
   @tail = @tail.prev 
   dummy
end

#insert_head(value) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/tdd/dll_etiqueta.rb', line 12

def insert_head(value)
   
   nodo = Node.new(value,nil,nil)
   
   if(@head == nil)
       @head = nodo
       @tail = nodo
   else
       @head.prev = nodo
       nodo.next = @head
       @head = nodo
   end
    
end

#insert_tail(value) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/tdd/dll_etiqueta.rb', line 27

def insert_tail(value)
   
   nodo = Node.new(value,nil,nil)
   
   if(@tail ==nil)
       @tail=nodo
       @head=nodo
   else
       @tail.next=nodo
       nodo.prev=@tail
       @tail=nodo
   end
end

#to_sObject



59
60
61
62
63
64
65
# File 'lib/tdd/dll_etiqueta.rb', line 59

def to_s
   it = @head
   while it!=nil
      puts it.value.to_s
      it=it.next
   end
end