sortIdx

Posted By: hatten

sortIdx - 03/14/17 17:16

When using sortIdx I run into the problem that this function apparently checks the lookback period and yields and error if the number of elements of the array you wish to sort exceeds the lookback period. However I do wish to sort an array that is not a time series and whose dimension is unrelated to lookback issues. This function should be in file functions.c as it is declared in function.h. Unfortunately function.c is not part of the distribution, otherwise it would be easy to just copy the code for sortIdx and remove checklookback command, which I assume is the problem. Anyone has a code snippet for sorting as sortIdx does? The standard qsort c++ function is different as it rearranges the elements of the original array which I don't want.
Posted By: Smon

Re: sortIdx - 01/13/18 15:09

Same question here!


This doesn't work:


function main()
{
int n;
var myarray[4] = {1.5, 2.3, 0.1, 0.001};

int Idx = sortIdx(myarray, 4);

for(n=0, n < 4, n++)
{
printf("n%dth Index = %d",n,Idx[n]);
}


}
Posted By: oligodar

Re: sortIdx - 01/14/18 19:19

This code works for me:

Code:
function main(){
	int n;
	var myarray[4] = {1.5, 2.3, 0.1, 0.001};
	int* Idx = sortIdx(myarray, -4);
	for(n=0; n < 4; n++){
	    printf("\n%dth Index = %d",n,Idx[n]);
	}
}




in zorro 1.744
Posted By: jcl

Re: sortIdx - 01/15/18 09:58

AFAIK, sortIdx does not check the lookback period and the number of elements does not matter. Maybe you were using a very old Zorro version.
© 2024 lite-C Forums