anacondaq Posted July 3, 2013 Posted July 3, 2013 Sorry for my english, some question: I have many variables, for example a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p; all of them have different values (number) I need to find variable where number is bigger then all other. For example: set a,10; set b,54; set c,13; set d,0; set e,12; set f,9; set g,43; set h,2; set i,15; set j,13; set m,1512; set n,236; set o,51; set p,521; I need to find m variable. because it's have 1512, but before finding i need analize all another variables to get who have biggest value. Help me please. Quote
Euphy Posted July 3, 2013 Posted July 3, 2013 If you don't store the numbers in an array, the only way to do this without writing it out would be through storing the variable names in an array, and looping with getd() - extremely messy and unnecessarily resource-intensive. If these are character variables (i.e. you can't use an array), you can probably find a way to do this with an SQL function. Assuming all the variables are in an array, you can use an algorithm like this: set .@max, .@arr[0]; for(set .@i,1; .@i<getarraysize(.@arr); set .@i,.@i+1) { if (.@arr[.@i] > .@max) { set .@max, .@arr[.@i]; set .@ele, .@i; deletearray .@tie[0], getarraysize(.@tie); } else if (.@arr[.@i] == .@max) { if (!getarraysize(.@tie)) set .@tie[0], .@arr[.@ele]; set .@tie[getarraysize(.@tie)], .@i; } }And that'll give you your max, .@max; the element where it's located, .@ele; and an array of any elements it's equal to, .@tie[]. Quote
anacondaq Posted July 3, 2013 Author Posted July 3, 2013 Euphy, can you recommend for me maby some book with algorythms? Quote
Question
anacondaq
Sorry for my english, some question:
I have many variables, for example
a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p;
all of them have different values (number)
I need to find variable where number is bigger then all other.
For example:
set a,10;
set b,54;
set c,13;
set d,0;
set e,12;
set f,9;
set g,43;
set h,2;
set i,15;
set j,13;
set m,1512;
set n,236;
set o,51;
set p,521;
I need to find m variable. because it's have 1512, but before finding i need analize all another variables to get who have biggest value.
Help me please.
2 answers to this question
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.