public class Search {
public static <E>int search(E[] arr, E target) {
for (int i = 0; i < arr.length; i++)
if (arr[i].equals(target))
return i;
return -1;
}
public static void main(String[] args) {
Integer arr[] = {1,3,4,5,7,6,8,10,13,11};
int index = search(arr,11);
long satrtTime = System.nanoTime();
long endTime = System.nanoTime();
long Time = endTime - satrtTime;
System.out.println(index);
System.out.println(Time + "ns");
}
}
选择排序
最新推荐文章于 2024-07-17 06:30:00 发布