3 回答
TA贡献1719条经验 获得超6个赞
我解决了。显然,图书网站上提供的较新的图书馆与我所拥有的书有所不同。
我将主要功能更改如下:
import java.util.Arrays;
public class BinarySearch{
public static int rank(int key, int[] a)
{ // Array must be sorted.
int lo = 0;
int hi = a.length - 1;
while (lo <= hi)
{ // Key is in a[lo..hi] or not present.
int mid = lo + (hi - lo) / 2;
if (key < a[mid]) hi = mid - 1;
else if (key > a[mid]) lo = mid + 1;
else return mid;
}
return -1;
}
public static void main(String[] args)
{
In i = new In(args[0]);
In j = new In(args[1]);
int[] whitelist = i.readAllInts();
int[] iplist = j.readAllInts();
Arrays.sort(whitelist);
for (int key:iplist)
{ // Read key, print if not in whitelist.
if (rank(key, whitelist) < 0)
StdOut.println(key);
}
}
}
然后通过
"tinyW.txt" "tinyT.txt"
作为 @GDG612 指示的程序参数。
TA贡献1852条经验 获得超1个赞
右键单击您的程序并选择Run As -> Run Configurations...
然后单击(x)= Arguments
选项卡并将输入传递给程序下Program arguments
添加回答
举报