Originally Posted by
IHeartProgramming
...I'm getting funny output...
For starters, how about adding some print statements to make the program show you exactly what it is adding to the Lists? Maybe something like
for (int i = 0; i < num_vertex; ++i)
{
System.out.printf("Begin adding for i = %d\n", i);
while (sc.hasNextInt() && sc.nextInt() != -999)
{
adj_ls.add(i, new LinkedList< Integer>());
// For debugging: Use a temporary variable so that you can print it out
int temp = sc.nextInt();
System.out.printf("vertex %d: Adding %d to adj_ls\n", i, temp);
adj_ls.get(i).addLast(temp);
}
// Make sure you got the correct number in each list
System.out.printf("List for vertex %d has size = %d\n",
i, adj_ls.get(i).size());
}
See how it goes? Make the debug print statements verbose enough to let you know exactly what the printed stuff means at each step.
Cheers!
Z