1 registered members (Edgar_Herrera),
1,111
guests, and 1
spider. |
Key:
Admin,
Global Mod,
Mod
|
|
|
How to sort current values of multiple series
#449410
03/19/15 10:53
03/19/15 10:53
|
Joined: Apr 2014
Posts: 482 Sydney, Australia
boatman
OP
Senior Member
|
OP
Senior Member
Joined: Apr 2014
Posts: 482
Sydney, Australia
|
I have several separate series that I am using to measure volatility. I'd like to sort the current values of each series in ascending order and pick out the five highest values for use in another function. What is the best way to accomplish this in Lite-C? I've tried passing the current value of each series to an element in an array (myarray[] = {series1[0], series2[0], ... , series12[0]} and then using the qsort function:
#include <stdio.h>
function run()
{
var myarray[] = {2, 6, 1, 9, 52, 3};
qsort(myarray, 6, 8, compare);
}
This returns an error that seems to originate in stdio.h: Error in 'stdio.h' line 228: 'API' undeclared identifier < API(_fsopen,msvcrt) >. Can anyone suggest what I'm doing wrong, or a better approach to this problem? Thanks in advance
|
|
|
Re: How to sort current values of multiple series
[Re: boatman]
#449428
03/20/15 05:58
03/20/15 05:58
|
Joined: Sep 2013
Posts: 504 California
GPEngine
User
|
User
Joined: Sep 2013
Posts: 504
California
|
When including something #include <stdio.h> you must also always include #include <default.c> FIRST
default.c is only implicitly included if there are no other includes. yep.
So try #include <default.c> #include <stdio.h>
function run() { ... }
Last edited by GPEngine; 03/20/15 06:09.
|
|
|
Re: How to sort current values of multiple series
[Re: boatman]
#449437
03/20/15 14:57
03/20/15 14:57
|
Joined: Sep 2013
Posts: 504 California
GPEngine
User
|
User
Joined: Sep 2013
Posts: 504
California
|
Well, if it's efficiency you're concerned about... rub hands togetherSince you only need the top k values where k << N , you don't need to sort the whole list. O(N log N). You can use - Partial selection sort O(Nk)
- max-heap of k elements. O(N + k log N)
As for the compare function did you try something like qsort translated to lite-c?
|
|
|
Re: How to sort current values of multiple series
[Re: GPEngine]
#449438
03/20/15 15:51
03/20/15 15:51
|
Joined: Sep 2013
Posts: 504 California
GPEngine
User
|
User
Joined: Sep 2013
Posts: 504
California
|
jcl, add lines like these to every header file in your include/.
#ifndef API
INCLUDE_DEFAULT_C_FIRST // intentional compile failure
#endif
That way Boatman would have at least seen a clue in the cryptic compiler error
sort compiling..
Error in 'stdio.h' line 231:
'INCLUDE_DEFAULT_C_FIRST' undeclared identifier
and maybe not needed to waste a day in the forums.
|
|
|
Re: How to sort current values of multiple series
[Re: GPEngine]
#465611
05/05/17 18:34
05/05/17 18:34
|
Joined: Dec 2014
Posts: 204 Germany
Smon
Member
|
Member
Joined: Dec 2014
Posts: 204
Germany
|
I'm trying to use sortData with no success. What am I doing wrong?
function main()
{
var Data[6] = {1,7,10,0,12,19};
sortData (var* Data,6); //syntax error!
for (int i=0, i<6, i++)
{
printf("n%d, "Data[i]);
}
}
I'm working on a support and resistance indicator. The array will contain price values later on. This is why I declared the array as "var".
|
|
|
|