public boolean contains( T anEntry){
boolean found = false;
for ( int index = 0;!found && (index < length); index++) {
if(anEntry.equals( list[index])){
found = true;
}
}
return found;
}//end contains
一旦在数组中找到与待找元素匹配的第一个元素,就立刻退出循环。这种情况下found为true。
时间效率:
最好情况:O(1)
最坏情况:O(n)
平均情况: O(n/2),其实就是O(n)