"선형 검색을 위해 다음과 같은 일반적인 방법을 구현해야합니다."하지만 일반적인 배열을 가질 수는 없습니다. 나의 급우들 중 누구도 그것을 이해할 수 없었고 우리 반 친구들을위한 TA도 없었습니다. 이것이 가능한가요, 그렇다면 올바른 방향으로 나를 가리킬 수 있습니까? 당신은 자바에서 일반 배열 생성 할 수 있습니다 감사합니다일반 선형 검색
public static void main(String[] args){
Scanner scan = new Scanner(System.in);
String type = scan.next();
int length = scan.nextInt();
//checks the type and makes the appropriate array
if (type.equals("I")) {
int[] anArray = new int[length];
for (int i = 0; i<length; i++) {
anArray[i] = scan.nextInt();
}
int key = scan.nextInt();
linearSearch(anArray, key); //Error, the method is not applicable for the arguments
}
}
public static <E extends Comparable<E>> int linearSearch(E[] list, E key) {
for (int i = 0; i<list.length; i++) {
if (list[i].equals(key)) {
return i;
}
}
return 0;
}