Method: Lista#search

Defined in:
lib/pract/list.rb

#search(val) ⇒ Object

Returns position of val[from 1] or nil is not found.

Returns:

  • position of val[from 1] or nil is not found



97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# File 'lib/pract/list.rb', line 97

def search(val)
  num = 1
  point = @head
  while(point != @tail)
    if(point.val == val)
      return num
    else
      num = num+1
      point = point.next
    end
  end
  if @tail.val == val
    return num
  else return 0
  end
end