Results 1 to 3 of 3
  1. #1
    jihad is offline Member
    Join Date
    Oct 2011
    Posts
    24
    Rep Power
    0

    Default 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 11:50 AM. Reason: missing information

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    11,601
    Blog Entries
    7
    Rep Power
    17

    Default 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,

    Jos
    When people rob a bank they get a penalty; when banks rob people they get a bonus.

  3. #3
    DarrylBurke's Avatar
    DarrylBurke is offline Moderator
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    10,089
    Rep Power
    17

    Default Re: stack over flow eror.there is infinite loop because of recursion

    Why do they call it rush hour when nothing moves? - Robin Williams

Similar Threads

  1. how to end infinite loop
    By search4survival in forum New To Java
    Replies: 14
    Last Post: 10-25-2010, 08:59 AM
  2. Replies: 0
    Last Post: 10-05-2010, 08:12 PM
  3. stack over flow error
    By sara12345 in forum New To Java
    Replies: 3
    Last Post: 04-14-2010, 09:50 PM
  4. Infinite Loop
    By rclausing in forum New To Java
    Replies: 2
    Last Post: 01-23-2010, 10:11 PM
  5. java recursion infinite loop
    By tony404 in forum Advanced Java
    Replies: 9
    Last Post: 10-03-2008, 01:16 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •