int res1 = LinearSearch.search(data, 16); //自动转换泛型类,数组型不能 System.out.println(res1);
int res2 = LinearSearch.search(data, 666); System.out.println(res2); //以下代码可不需要----------------------------- Student[] students = {new Student("Alice"), new Student("Bob"), new Student("Charles")}; Student bob = new Student("bOb"); //不区分大小写 int res3 = LinearSearch.search(students, bob); System.out.println(res3); } }
long startTime = System.nanoTime(); for (int k = 0; k < 100; k++) LinearSearch.search(data, n); //自动转换泛型类,数组型不能
long endTime = System.nanoTime(); double time = (endTime - startTime) / 1000000000.0; //单位是纳秒 浮点数加零 计算时间复杂 可以判断算法性能 System.out.println("n =" + n + ", 1000 runs :" + time + " s"); //打印出花费时间 } // int res2 = LinearSearch.search(data, 666); // System.out.println(res2);
Student[] students = {new Student("Alice"), new Student("Bob"), new Student("Charles")}; Student bob = new Student("bOb"); //不区分大小写 int res3 = LinearSearch.search(students, bob); System.out.println(res3); } }
评论