Results 1 to 4 of 4
Thread: stack over flow error
- 04-14-2010, 11:23 AM #1
Member
- Join Date
- Dec 2009
- Posts
- 59
- Rep Power
- 0
stack over flow error
hello
I'm facing error "stack over flow" when obtaining results of recursion fuction
I have tested the recursion fuction on medium data size and it works fine and the results are correct but for large data it prints some of the results then an error said "stackOverflowError" is occurd
I need to complete the results of this large data is there is away to do that
thanks alot
- 04-14-2010, 08:27 PM #2
Senior Member
- Join Date
- Mar 2010
- Posts
- 953
- Rep Power
- 4
Show us your code (and remember to use CODE tags). You will get stack overflow if you try to recurse too deeply. But maybe there's a way to improve your algorithm, or maybe there's something we'll catch that you didn't.
-Gary-
- 04-14-2010, 08:58 PM #3
Member
- Join Date
- Dec 2009
- Posts
- 59
- Rep Power
- 0
the code shown aboveJava Code:static void Reordering_solution(){ for (int y=0; y<vector_SA.size()-1; y++){ not_visited.clear(); boolean flag=false; nex_min_sw_same_dir(vect_ordered_temp,next_point); if (vect_min.size()==1){ test_after_filling_ordering.add(vect_min.get(0).toString()); _2nd_min_element=vect_min.get(0).toString(); vect_ordered_temp.removeElement(next_point); next_point=_2nd_min_element; }// end if condition if (vect_min.size()>1){ for (int k=0;k<vect_min.size();k++){ vect_min_s= vect_min.get(k).toString(); if (first_vect_min!=null && vect_min_s.equals(first_vect_min)){ for (int m=k+1;m< vect_min.size();m++) not_visited.add(vect_min.get(m).toString());} if (first_vect_min==null ){ not_visited.add(vect_min.get(k).toString());} } if (not_visited.size()==0){ y=vector_SA.size()-1; vect_min_s= null;} if (not_visited.size()!=0){ vect_min_s=not_visited.get(0).toString(); if (not_visited.size()==vect_min.size()){ if (total_3.size()>not_visited.size() ){ for (int i=0; i< total_3.size();i++){ if (total_3.get(i).toString().equals(not_visited.get(0).toString()) && total_3.get(i+1).toString().equals(not_visited.get(1).toString())){ flag=true; y=vector_SA.size(); }} } if (flag==false){ for (int h=0; h<not_visited.size();h++){ for (int g = 0; g < test_after_filling_ordering.size(); g++) { total_1.add(test_after_filling_ordering.get(g).toString());} total_1.add( "Empty"); total_1.add(not_visited.get(h).toString()); total_1.add( "Empty"); for (int g = 0; g < vect_ordered_temp.size(); g++) { total_1.add(vect_ordered_temp.get(g).toString());} total_1.add("Empty"); }}} if (flag==false){ test_after_filling_ordering.add(vect_min_s); _2nd_min_element=vect_min_s; vect_ordered_temp.removeElement(next_point); next_point=_2nd_min_element;}}} if ( test_after_filling_ordering.size()==vector_SA.size()){ y=vector_SA.size()-1; System.out.println(" The Reordering string is : "); System.out.println(test_after_filling_ordering);}} test_after_filling_ordering.clear(); vect_ordered_temp.clear(); copy_min.clear(); test_pattern1.clear(); test_pattern2.clear(); test_pattern3.clear(); if(total_1.size()==0) return; for (int j=0; j< total_1.size();j++){ if (!total_1.get(j).toString().equals("Empty") && total_1.get(j).toString()!=null){ test_pattern1.add(total_1.get(j).toString());} if (total_1.get(j).toString().equals("Empty")){ stop=j; j=total_1.size();} } stop++; test_pattern2.add(total_1.get(stop).toString()); stop++; total_3.add(test_pattern2); stop++; for (int j=stop; j< total_1.size();j++){ if (!total_1.get(j).toString().equals("Empty") && total_1.get(j).toString()!=null){ test_pattern3.add(total_1.get(j).toString());} if (total_1.get(j).toString().equals("Empty")){ stop_2=j; j=total_1.size();} } if(total_1.size()==stop_2+1) return; for (int j=stop_2+1; j< total_1.size();j++){ if (!total_1.get(j).toString().equals("Empty")){ test_after_filling_ordering.add(total_1.get(j).toString());} if (total_1.get(j).toString().equals("Empty")){ stop_3=j; j=total_1.size();} } stop_3++; copy_min.add(total_1.get(stop_3).toString()); stop_3++; stop_3++; for (int j=stop_3; j< total_1.size();j++){ if (!total_1.get(j).toString().equals("Empty")){ vect_ordered_temp.add(total_1.get(j).toString());} if (total_1.get(j).toString().equals("Empty")){ stop_4=j; j=total_1.size();} } total_2.clear(); stop_4++; for (int j=stop_4; j< total_1.size();j++){ total_2.add(total_1.get(j).toString());} total_1.clear(); for (int g = 0; g < test_after_filling_ordering.size(); g++) { total_1.add(test_after_filling_ordering.get(g).toString());} total_1.add("Empty"); total_1.add(copy_min.get(0).toString()); total_1.add("Empty"); for (int g = 0; g < vect_ordered_temp.size(); g++) { total_1.add(vect_ordered_temp.get(g).toString());} total_1.add("Empty"); if (total_2.size()!=0){ for (int j=0; j< total_2.size();j++){ total_1.add(total_2.get(j).toString());}} next_point=test_after_filling_ordering.get(test_after_filling_ordering.size()-1).toString(); if (test_pattern1.equals(test_after_filling_ordering)){ first_vect_min=test_pattern2.get((test_pattern2.size()-1)).toString();} if (!test_pattern1.equals(test_after_filling_ordering)) first_vect_min=null; Reordering_solution(); }
thanks
- 04-14-2010, 09:50 PM #4
Senior Member
- Join Date
- Mar 2010
- Posts
- 953
- Rep Power
- 4
Ahh, this one. I tried to read through your code before, and just found it too long and complicated to follow (at least without charging exorbitant fees :)). This is partly because of formatting, and partly because of cryptic names and lack of comments. Methods (especially recursive methods) should be short and simple. For a recursive method, the idea is basically:
- Test if the "base case" has been reached, meaning no further recursion is necessary
- If so, return the appropriate value
- If not, do minimal processing for this step, and hand off the rest of the work to another copy of yourself
I can't tell exactly what your code is trying to do, but it seems to be doing a whole lot more than it should be for a recursive method. Can you tell us what you're trying to accomplish, maybe in pseudo-code?
-Gary-
Similar Threads
-
stack overflow error, i want to call a method within itself not using recursion tho
By bigboi26 in forum New To JavaReplies: 1Last Post: 03-17-2010, 05:25 AM -
Graphics2D: stack overflow error
By rosh72851 in forum New To JavaReplies: 11Last Post: 10-15-2008, 09:01 PM -
program flow
By loktamu in forum AWT / SwingReplies: 1Last Post: 09-17-2008, 04:52 PM -
error stack when I try to execute my code
By paty in forum New To JavaReplies: 1Last Post: 08-02-2007, 08:32 PM -
Java + information flow 3.0
By levent in forum Java SoftwareReplies: 0Last Post: 05-20-2007, 09:09 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks