Method: Lista#remove

Defined in:
lib/pract/list.rb

#remove(val) ⇒ Object

Remove an element

Parameters:

  • as the value we want to remove



60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/pract/list.rb', line 60

def remove (val)
  if (@head != nil)
      if(@head == @tail) && (@head.val == val)
      @head = nil
      @tail = nil
    elsif (@head.val == val)
      remove_first
    elsif (@tail.val == val)
      remove_last
    else
      point = @head
      while (point.next != nil) && (point.val != val)
        point = point.next
      end
      if point != @tail
        before = point.prev
        after = point.next
        before.next = after
        after.prev = before
        point.prev = nil
        point.next = nil
      end
    end
  end
end