Write a method called indexOf that accepts a value as a parameter and returns the index in the list of the first occurrence of that value, or –1 if the value is not found in the list.
Add the following method to the LinkedIntList class from this chapter.
Implementation of indexOf method:
public int indexOf(int value)
{
int index = 0;
ListNode current = front;
while(current != null)
{
if(current.data == value)
{
return index;
}
index++;
current = current.next;
}
return -1;
}