wrong results with recursion
hello
I'm writing recursive function but I have problem with it
the recursive functions should do the following: it does reordering according to criteria and writes results on file if the file is empty it should stop
Code:
static void Reordering_solution(FileWriter writer_rordering_out,File reordering){
try {
for (int y=0; y<vector_SA.size()-1; y++){
visited.clear();
nex_min_sw_same_dir(vect_ordered_temp,next_point);
System.out.println(vect_min.size());
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;
}
System.out.println(" the test vector after fillling is "+test_after_filling_ordering);
if (vect_min.size()>1){
for (int k=0;k<vect_min.size();k++){
System.out.println(" the vector min is "+ vect_min);
vect_min_s= vect_min.get(k).toString();
System.out.println(" the vector min s is "+ vect_min_s);
if (first_vect_min !=null && vect_min_s.equals(first_vect_min)){
if(k==0){
visited.add(vect_min.get(0).toString());}
if (k>0 && k<vect_min.size()-1){
for (int m=0; m==k;m++){
visited.add(vect_min.get(m).toString());}}
if (k==vect_min.size()-1){
for (int m=0; m==k;m++){
visited.add(vect_min.get(m).toString());}}}
if (first_vect_min ==null || (!vect_min_s.equals(first_vect_min))){
visited.add(vect_min.get(k).toString());
k=vect_min.size();}}
if (vect_min.size()!=visited.size()){
for (int g = 0; g < test_after_filling_ordering.size(); g++) {
writer_rordering_out.write(test_after_filling_ordering.get(g).toString());
writer_rordering_out.write("\r\n");}
writer_rordering_out.write("Empty");
writer_rordering_out.write("\r\n");
for (int g = 0; g < visited.size(); g++) {
writer_rordering_out.write(visited.get(g).toString());
writer_rordering_out.write("\r\n");}
writer_rordering_out.write("Empty");
writer_rordering_out.write("\r\n");
System.out.println("The visited vect is "+ visited);
System.out.println(" after filling r "+test_after_filling_ordering);
for (int g = 0; g < vect_ordered_temp.size(); g++) {
writer_rordering_out.write(vect_ordered_temp.get(g).toString());
writer_rordering_out.write("\r\n");}
writer_rordering_out.write("Empty");
writer_rordering_out.write("\r\n");}
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;
System.out.println(" the vect min is "+ vect_min);
System.out.println(test_after_filling_ordering); }
if ( test_after_filling_ordering.size()==vector_SA.size()){
y=vector_SA.size()-1;
System.out.println();
System.out.println(" The Reordering string is : ");
System.out.println(test_after_filling_ordering);
System.out.println();}}
writer_rordering_out.close();
test_after_filling_ordering.clear();
vect_ordered_temp.clear();
copy_min.clear();
test_ordering_1.clear();
test_ordering_2.clear();
test_ordering_3.clear();
Scanner inFile_77= new Scanner(new FileInputStream(reordering));
BufferedReader reader_reordering_sub = new BufferedReader(new FileReader(reordering));
line_reodering = null;
line_reodering = reader_reordering_sub.readLine();
line_reodering=inFile_77.nextLine();
while (inFile_77.hasNextLine()){
for (int j=0; j< 200;j++){
if (!line_reodering.contains("Empty") && inFile_77.hasNextLine()){
test_after_filling_ordering.add(line_reodering);
line_reodering=inFile_77.nextLine();}
if (line_reodering.contains("Empty")){
j=200;}
}
System.out.println(" the tst "+ test_after_filling_ordering);
line_reodering=inFile_77.nextLine();
if (!line_reodering.contains("Empty") && inFile_77.hasNextLine()){
copy_min.add(line_reodering);
line_reodering=inFile_77.nextLine();}
System.out.println(" the copy "+ copy_min);
line_reodering=inFile_77.nextLine();
for (int j=0; j< 200;j++){
if (!line_reodering.contains("Empty") && inFile_77.hasNextLine()){
vect_ordered_temp.add(line_reodering);
line_reodering=inFile_77.nextLine();}
if (line_reodering==("Empty")){
j=200;}
}
System.out.println(" the ordered "+ vect_ordered_temp);
File data1= new File("data");
FileWriter writer_rodering_2 = new FileWriter("data");
while (inFile_77.hasNextLine()){
line_reodering=inFile_77.nextLine();
System.out.println(" the line is "+ line_reodering);
writer_rodering_2.write(line_reodering);
writer_rodering_2.write("\r\n");}
next_point=test_after_filling_ordering.get(test_after_filling_ordering.size()-1).toString();
first_vect_min=copy_min.get(copy_min.size()-1).toString();
Reordering_solution(writer_rodering_2 ,data1);
}inFile_77.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
for the method nex_min_sw_same_dir(vect_ordered_temp,next_point);
it takes vector(vect_ordered_temp) and string (next_point) and it gives the vector( vect_min).
if vect_min==1 it adds this element to the ordering vector( test_after_filling_ordering).
if vect_min>1 then it must do reordering for the first element and then after finishing reordering do the reordering for the next element and so on
I really need your suggestion how can I solve my problem this recursvie function doesn't work properly
thanks