Here comes the function with which I have a problem:
ivec sort_index( vec list, int length ) {
ivec index;
index = zeros_i(N);
float temp = 0;
int temp2 = 0;
for ( int j = 0 ; j<N ; j++){
index[j]=j;
}
int i = 1;
while ( i < length ){
for (int k = i; list[k - 1] > list[k]; k--){
temp = list[k - 1];
list[k - 1] = list[k];
list[k] = temp;
temp2 = index[k - 1];
index[k - 1] = index[k];
index[k] = temp2;
}
i++;
}
return index;
Nmatches lengthand is the lengthlist
I debugged this code in Visual Studio 2012, and I found that there is a problem in the line:
for (int k = i; list[k - 1] > list[k]; k--){
The problem is the Out Of Range error.
I can provide a call stack if necessary.
Can someone help me change this loop whileand forto keep the functionality of the function sort_index()?
Yours faithfully,
Jr
source
share