MVSFORUMS.com Forum Index MVSFORUMS.com
A Community of and for MVS Professionals
 
 FAQFAQ   SearchSearch   Quick Manuals   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

finding highest value in an array

 
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Application Programming
View previous topic :: View next topic  
Author Message
mfuser
Banned


Joined: 01 Mar 2005
Posts: 105
Topics: 58

PostPosted: Tue Jan 31, 2006 7:45 am    Post subject: finding highest value in an array Reply with quote

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
View user's profile Send private message
vst
Beginner


Joined: 23 Jan 2006
Posts: 11
Topics: 0

PostPosted: Tue Jan 31, 2006 9:40 am    Post subject: Reply with quote

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
View user's profile Send private message
Mervyn
Moderator


Joined: 02 Dec 2002
Posts: 415
Topics: 6
Location: Hove, England

PostPosted: Tue Jan 31, 2006 9:47 am    Post subject: Reply with quote

I agree. Try searching for "bubble sort" and/or "shell sort".
_________________
The day you stop learning the dinosaur becomes extinct
Back to top
View user's profile Send private message
kolusu
Site Admin
Site Admin


Joined: 26 Nov 2002
Posts: 12378
Topics: 75
Location: San Jose

PostPosted: Tue Jan 31, 2006 10:39 am    Post subject: Reply with quote

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
View user's profile Send private message Send e-mail Visit poster's website
mfuser
Banned


Joined: 01 Mar 2005
Posts: 105
Topics: 58

PostPosted: Tue Jan 31, 2006 11:54 am    Post subject: Reply with quote

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
View user's profile Send private message
bauer
Intermediate


Joined: 10 Oct 2003
Posts: 317
Topics: 50
Location: Germany

PostPosted: Wed Feb 01, 2006 1:35 am    Post subject: Reply with quote

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
View user's profile Send private message
mfuser
Banned


Joined: 01 Mar 2005
Posts: 105
Topics: 58

PostPosted: Wed Feb 01, 2006 1:57 am    Post subject: Reply with quote

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
View user's profile Send private message
shekar123
Advanced


Joined: 22 Jul 2005
Posts: 528
Topics: 90
Location: Bangalore India

PostPosted: Wed Feb 01, 2006 12:44 pm    Post subject: Reply with quote

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
View user's profile Send private message
vst
Beginner


Joined: 23 Jan 2006
Posts: 11
Topics: 0

PostPosted: Mon Feb 06, 2006 6:36 am    Post subject: Reply with quote

shekar123,

since nobody interested in continuation Smile , I supply you with some further reasonings:

Code:

I IS                        8

means
Code:

   PUT SKIP LIST ('I IS ',I);                                   
   IF ABC(I) < ABC(I + 1) THEN       /* I=8;I+1=9; ABC(I+1)=ABC(9) is obviously not defined (points out of data scope) */

I would propose to start with one of well-known methods http://en.wikisource.org/wiki/Bubble_sort
D.Knuth' classic book http://en.wikipedia.org/wiki/The_Art_of_Computer_Programming has explained most of them
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Application Programming All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


MVSFORUMS
Powered by phpBB © 2001, 2005 phpBB Group