I'm having problem when i'm adding node in Array of LinkedList.
int vertices = 100;
LinkedList[] AdjList = new LinkedList[vertices+1];
for (i = 1; i <= vertices; ++i) {
for (j = 1; j <= 6 && j + i <= vertices; ++j) {
AdjList[i].add(j); //Error occurs here.
}
}
Answer
You need to create the list before inserting into it. In your first for loop add this line, before the second for loop
AdjList[i] = new LinkedList();
No comments:
Post a Comment