View previous topic :: View next topic |
Author |
Message |
mfuser Banned
Joined: 01 Mar 2005 Posts: 105 Topics: 58
|
Posted: Tue Jan 31, 2006 7:45 am Post subject: finding highest value in an array |
|
|
Hai All,
I have an array declared and i have assigned values to the array like below:
Code: |
DCL LIST (08) FIXED DECIMAL (2);
DCL MAXVALUE FIXED DECIMAL (2);
LIST(1)= 20;
LIST(2)= 5;
LIST(3)= 10;
LIST(4)= 30;
LIST(5)= 63;
LIST(6)= 15;
LIST(7)= 31;
LIST(8)= 70;
PUT SKIP LIST (LIST);
MAXVALUE = MAX(1,2);
PUT SKIP LIST (MAXVALUE);
|
I want to find the maximum value in the array which should be 83 and i also want to find the nth highest value for example if i want to find 6 th highest,how can i do that which should be 15 ? |
|
Back to top |
|
 |
vst Beginner
Joined: 23 Jan 2006 Posts: 11 Topics: 0
|
Posted: Tue Jan 31, 2006 9:40 am Post subject: |
|
|
Answer seems too obvious for me, but may be I miss something?
Quote: |
to find the nth highest value for example if i want to find 6 th highest,how can i do that which should be 15 ?
|
Quoted text is a definition of SORT operation, is'nt it? |
|
Back to top |
|
 |
Mervyn Moderator

Joined: 02 Dec 2002 Posts: 415 Topics: 6 Location: Hove, England
|
Posted: Tue Jan 31, 2006 9:47 am Post subject: |
|
|
I agree. Try searching for "bubble sort" and/or "shell sort". _________________ The day you stop learning the dinosaur becomes extinct |
|
Back to top |
|
 |
kolusu Site Admin

Joined: 26 Nov 2002 Posts: 12378 Topics: 75 Location: San Jose
|
Posted: Tue Jan 31, 2006 10:39 am Post subject: |
|
|
Mf_user,
try this
Code: |
DCL LIST (08) FIXED DECIMAL (2);
DCL MAXVALUE FIXED DECIMAL (2);
LIST(1)= 20;
LIST(2)= 05;
LIST(3)= 10;
LIST(4)= 30;
LIST(5)= 63;
LIST(6)= 15;
LIST(7)= 31;
LIST(8)= 70;
PUT SKIP LIST (LIST);
MAXVALUE = MAX(LIST(8)) ;
PUT SKIP;
PUT SKIP LIST(MAXVALUE) ;
|
Hope this helps...
Cheers
Kolusu _________________ Kolusu
www.linkedin.com/in/kolusu |
|
Back to top |
|
 |
mfuser Banned
Joined: 01 Mar 2005 Posts: 105 Topics: 58
|
Posted: Tue Jan 31, 2006 11:54 am Post subject: |
|
|
Kolusu,
I have tried your code and i am gettting the result for maximum value as 70 which should have been 83 as the max value.
Code: |
DCL LIST (08) FIXED DECIMAL (2);
DCL MAXVALUE FIXED DECIMAL (2);
LIST(1)= 20;
LIST(2)= 05;
LIST(3)= 10;
LIST(4)= 30;
LIST(5)= 83;
LIST(6)= 15;
LIST(7)= 31;
LIST(8)= 70;
PUT SKIP LIST (LIST);
MAXVALUE = MAX(LIST(08));
PUT SKIP;
PUT SKIP LIST (MAXVALUE);
|
OUTPUT
Code: |
20 5 10 30 83
15 31 70
70
|
|
|
Back to top |
|
 |
bauer Intermediate
Joined: 10 Oct 2003 Posts: 317 Topics: 50 Location: Germany
|
Posted: Wed Feb 01, 2006 1:35 am Post subject: |
|
|
mfuser,
is your first sample you coded LIST(5) = 63, in your post dated 31. Jan you are coding LSIT(5) = 83 ?! |
|
Back to top |
|
 |
mfuser Banned
Joined: 01 Mar 2005 Posts: 105 Topics: 58
|
Posted: Wed Feb 01, 2006 1:57 am Post subject: |
|
|
Bauer,
Sorry for the mistake as i typed in wrongly .It should have been LIST(05) = 83 instead of 63 and the maximum value should be 83. |
|
Back to top |
|
 |
shekar123 Advanced
Joined: 22 Jul 2005 Posts: 528 Topics: 90 Location: Bangalore India
|
Posted: Wed Feb 01, 2006 12:44 pm Post subject: |
|
|
Kolusu & mfuser,
I have made some modifications in the code and i am first trying to sort the array but i am getting S0C7 error.Can you guys can help me out what exactly is the problem.I am trying to move a value to a temporary variable but the value is taking constant value of 5.I am trying to debug the problem that is why i am using PUT SKIP LIST but the value of temporary variable is 5.Please guide me ahead to proceed.
Code: |
DCL ABC (08) FIXED DECIMAL (2) INIT (20,05,10,30,83,15,31,70);
DCL SYSPRINT FILE PRINT;
DCL I FIXED DECIMAL (2) INIT (1);
DCL TEMP FIXED DECIMAL (2) INIT (0);
DO UNTIL(I > 8);
PUT SKIP LIST ('I IS ',I);
IF ABC(I) < ABC(I + 1) THEN
DO;
PUT SKIP LIST ('ABC(I)',ABC(I));
TEMP = ABC(I);
PUT SKIP LIST ('TEMP IS ',TEMP);
ABC(I) = ABC(I + 1);
PUT SKIP LIST ('ABC(I)',ABC(I));
ABC(I + 1) = TEMP;
PUT SKIP LIST ('ABC(I + 1)',ABC(I+1));
END;
ELSE;
I = I + 1;
END;
PUT SKIP LIST ('GREATEST IS ',ABC(8));
|
Code: |
I IS 1
I IS 2
ABC(I) 5
TEMP IS 5
ABC(I) 10
ABC(I + 1) 5
I IS 3
ABC(I) 5
TEMP IS 5
ABC(I) 30
ABC(I + 1) 5
I IS 4
ABC(I) 5
TEMP IS 5
ABC(I) 83
ABC(I + 1) 5
I IS 5
ABC(I) 5
TEMP IS 5
ABC(I) 15
ABC(I + 1) 5
I IS 6
ABC(I) 5
TEMP IS 5
ABC(I) 31
ABC(I + 1) 5
I IS 7
ABC(I) 5
TEMP IS 5
ABC(I) 70
ABC(I + 1) 5
I IS 8
|
_________________ Shekar
Grow Technically |
|
Back to top |
|
 |
vst Beginner
Joined: 23 Jan 2006 Posts: 11 Topics: 0
|
|
Back to top |
|
 |
|
|