my main file has following code
n=10;
k=100;
solution_archiv *sa = new solution_archiv[k];
int *initial_positions = new int(n);
cout<<"--------top ten indexes----------"<<endl;
initial_positions = select_index(sa, k, n);
for(int i=0; i<no_of_ants; i++){
cout<<initial_positions[i]<<endl;
}
and my func.cpp contains
int* select_index(solution_archiv *sa, int k, int n)
{
int temp;
double *prob = new double(k);
int *index = new int(k);
int *ret_index = new int(n);
for (int i = 0; i < k; i++)
{
prob[i] = Probability_of_Solution(sa, i, k);
}
cout<<"\n";
/* set up index array for original sequence */
for (int i = 0; i < k; i++)
{
index[i] = i;
}
/* Sort according to health. Will swap indx values so that
index[0], index[1], ... , points to values of health and
bacteria so that they can be printed out in sorted order.
*/
/*sorting in ascending order of health */
for (int i = 0; i < k - 1; i++)
{
for (int j = i + 1; j < k; j++)
{
if (prob[index[j]] > prob[index[i]])
{
temp = index[j];
index[j] = index[i];
index[i] = temp;
}
}
}
cout<<"Original values showing original positions:\n";
for (int i = 0; i < k; i++)
{
cout<<i<<":"<< "prob = "<<prob[i]<<endl;
}
cout<<"\n";
cout<<"Top ten elements and their original indexes:\n";
for (int i = 0; i < n; i++)
{
ret_index[i] = index[i];
}
return ret_index;
}
i don't know why it is giving unexpected value of the indexes while if i am printing ret_index in the func.cpp itself it is giving correct result. Please help me out.