Results 1 to 4 of 4
  1. #1
    sara12345 is offline Member
    Join Date
    Dec 2009
    Posts
    59
    Rep Power
    0

    Default 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

  2. #2
    gcalvin is offline Senior Member
    Join Date
    Mar 2010
    Posts
    952
    Rep Power
    5

    Default

    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-

  3. #3
    sara12345 is offline Member
    Join Date
    Dec 2009
    Posts
    59
    Rep Power
    0

    Default

    Java 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();
    }
    the code shown above
    thanks

  4. #4
    gcalvin is offline Senior Member
    Join Date
    Mar 2010
    Posts
    952
    Rep Power
    5

    Default

    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:
    1. Test if the "base case" has been reached, meaning no further recursion is necessary
    2. If so, return the appropriate value
    3. 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

  1. Replies: 1
    Last Post: 03-17-2010, 06:25 AM
  2. Graphics2D: stack overflow error
    By rosh72851 in forum New To Java
    Replies: 11
    Last Post: 10-15-2008, 10:01 PM
  3. program flow
    By loktamu in forum AWT / Swing
    Replies: 1
    Last Post: 09-17-2008, 05:52 PM
  4. error stack when I try to execute my code
    By paty in forum New To Java
    Replies: 1
    Last Post: 08-02-2007, 09:32 PM
  5. Java + information flow 3.0
    By levent in forum Java Software
    Replies: 0
    Last Post: 05-20-2007, 10:09 AM

Posting Permissions

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