I apologize for a rookie question. I am trying to run the Java programs in Eclipse given in the Algorithms, 4th edition book by Robert Sedgewick and Kevin Wayne: https://algs4.cs.princeton.edu/home/
I am having trouble with input arguments to the programs.
For example for the following program:
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)
{
int[] whitelist = In.readInts(args[0]);
Arrays.sort(whitelist);
while (!StdIn.isEmpty())
{ // Read key, print if not in whitelist.
int key = StdIn.readInt();
if (rank(key, whitelist) < 0)
StdOut.println(key);
}
}
}
The input arguments are:
% java BinarySearch tinyW.txt < tinyT.txt
I don't know where to pass input arguments in Eclipse. Any help will be appreciated.
int key = StdIn.readInt();
This will not work. Unless you use thelib
. – Khan Saab