class LinkedList

Clase lista

Attributes

head[RW]

Variables

tail[RW]

Variables

Public Class Methods

new() click to toggle source

Constructor

# File lib/prct06/list.rb, line 15
def initialize
  @head = @tail = nil
end

Public Instance Methods

add(value, *more) click to toggle source

AƱadir nodos a la lista

# File lib/prct06/list.rb, line 20
def add (value, *more)

  node = Node.new(value)

  @tail = node if @tail.nil?

  @head.next = node unless @head.nil?
  node.prev = @head unless @head.nil?

  @head = node

  more.each do |i|
    node2 = Node.new(i)
    @head.next = node2
    node2.prev = @head
    @head = @head.next
  end
end
each() { |value| ... } click to toggle source
# File lib/prct06/list.rb, line 66
def each
  aux = @tail

  while aux != nil do
    yield aux.value
    aux = aux.next
  end
end
empty() click to toggle source
# File lib/prct06/list.rb, line 46
def empty()
  emptyy = false
  emptyy = true if @head.nil?

  return emptyy
end
pop() click to toggle source

Saca la cabeza de la lista

# File lib/prct06/list.rb, line 40
def pop()
  node = @head
  @head = @head.next
  return node
end
to_s() click to toggle source

Mostrar la lista

# File lib/prct06/list.rb, line 54
def to_s
  $i = @tail

  while ($i != nil) do
    puts "#{$i.value}"
    $i = $i.next
  end

  puts "CABEZA: #{@head.value}"
  puts "COLA: #{@tail.value}"
end