Results 1 to 3 of 3
- 01-11-2013, 12:48 PM #1
Member
- Join Date
- Oct 2011
- Posts
- 24
- Rep Power
- 0
stack over flow eror.there is infinite loop because of recursion
there is infinite loop because of recursion but where is get into infinite loop I couldnt understand
Scanner input = new Scanner(System.in);
List<node> list = new LinkedList<node>();
Random randomGenerator = new Random();
List<node> queue = new LinkedList<node>();
int time = 0;
int counter2=0;
public void dfs() {
for (int i = 0; i < list.size(); i++) {
list.get(i).setcolor("white");
list.get(i).setpredecessor(null);
}
time = 0;
for (int i = 0; i < list.size(); i++) {
if (list.get(i).getcolor().equals("white")) {
dfsvisit(i);
}
for (int s = 0; s < list.size(); s++) {
System.out.println(list.get(s).getnode() + " visit time is " + list.get(s).visiTTime);
System.out.println(list.get(s).getnode() + " finish time is " + list.get(s).FinishTime);
}
}
}
public void dfsvisit(int i) {
counter2++;
System.out.println("\ncounter2 "+counter2);
time = time + 1;
list.get(i).visiTTime = time;
list.get(i).setcolor("gray");
for (int v = 0; v < list.get(i).connectedVertexes.size(); v++) {
if (list.get(i).connectedVertexes.get(v).getcolor().e quals("white"))
{
list.get(i).connectedVertexes.get(v).setpredecesso r(list.get(i));
dfsvisit(v);
}
}
list.get(i).setcolor("black");
time = time + 1;
list.get(i).FinishTime = time;
}Last edited by jihad; 01-11-2013 at 12:50 PM. Reason: missing information
- 01-11-2013, 01:05 PM #2
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 14,422
- Blog Entries
- 7
- Rep Power
- 29
Re: stack over flow eror.there is infinite loop because of recursion
Add a couple of System.out.println( ... ) statements and run your algorithm on a well known (small) network/graph and see what happens.
kind regards,
JosBuild a wall around Donald Trump; I'll pay for it.
- 01-11-2013, 02:27 PM #3
Re: stack over flow eror.there is infinite loop because of recursion
If you're forever cleaning cobwebs, it's time to get rid of the spiders.
Similar Threads
-
how to end infinite loop
By search4survival in forum New To JavaReplies: 14Last Post: 10-25-2010, 09:59 AM -
Looking at the values in the stack during recursion
By luke in forum New To JavaReplies: 0Last Post: 10-05-2010, 09:12 PM -
stack over flow error
By sara12345 in forum New To JavaReplies: 3Last Post: 04-14-2010, 10:50 PM -
Infinite Loop
By rclausing in forum New To JavaReplies: 2Last Post: 01-23-2010, 11:11 PM -
java recursion infinite loop
By tony404 in forum Advanced JavaReplies: 9Last Post: 10-03-2008, 02:16 PM
Bookmarks