Форум » C/C++ для начинающих (C/C++ for beginners) » Separating the loops or un-nesting the loops » Ответить

Separating the loops or un-nesting the loops

asq19: Hi I've a loop inside another loop and would like to separate them into two different loops and keep the same functionality, since I'm having trouble with probably memory allocation Here are the code: ofstream myfile1; ofstream grid; myfile1.open ("fine-time.txt"); grid.open ("grid.txt"); //myfile << "Writing this to a file.\n"; double temp=0; myfile1 << setw(16) ; for (int k=1; k<nz+1;k++){ for (int j=1; j<ny+1;j++){ for (int i=1; i<nx+1;i++){ index= (k-1) * nx * ny +(j-1) * (nx) + (i-1) ; /*if(Final_T[index]==inf){ Final_T[index]=1.; }*/ myfile1 <<Final_T[index]<< setw(16) ; // save fine scale time time_orig[index]= Final_T[index]; //myfile1 <<F[index]<< setw(16) ; temp=temp+Final_T[index]; } myfile1 << endl ; } } //variables for tempery values and to count # of grids double temp1,val=0.0; int count=0; //sorting Final_T array using buble sort algorithm for(i=0;i<npixels;i++){ for(j=0;j<npixels-1;j++){ if(Final_T[j]>Final_T[j+1]){ temp1=Final_T[j+1]; Final_T[j+1]=Final_T[j]; Final_T[j]=temp1; } } } //write in to gird.txt for(i=0;i<npixels;i++){ if(val<Final_T){ grid<<Final_T[i-1]<<" --> "<<count-1<<endl; val=Final_T; } count++; } grid<<Final_T[i-1]<<" --> "<<count<<endl; myfile1.close(); grid.close(); cout<<"Summation-time = "; cout<<temp/1000;

Ответов - 0



полная версия страницы