Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
28
Task/Averages-Mode/XPL0/averages-mode.xpl0
Normal file
28
Task/Averages-Mode/XPL0/averages-mode.xpl0
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
proc Mode(Size, Array); \Show the mode(s) of Array
|
||||
int Size, Array;
|
||||
int List, Count I, J, K, Max;
|
||||
[List:= Reserve(Size*4); \4 bytes per integer
|
||||
Count:= Reserve(Size*4);
|
||||
K:= 0;
|
||||
for I:= 0 to Size-1 do
|
||||
[for J:= 0 to K-1 do
|
||||
if List(J) = Array(I) then \item is in List
|
||||
[Count(J):= Count(J)+1; \ so increment its count
|
||||
J:= Size;
|
||||
];
|
||||
if J = K then \not already in List
|
||||
[List(K):= Array(I);
|
||||
Count(K):= 1;
|
||||
K:= K+1;
|
||||
];
|
||||
];
|
||||
Max:= 0; \find maximum count
|
||||
for J:= 0 to K-1 do
|
||||
if Count(J) > Max then
|
||||
Max:= Count(J);
|
||||
for J:= 0 to K-1 do \show Array item(s) with Max Count
|
||||
if Count(J) = Max then
|
||||
[IntOut(0, List(J)); ChOut(0, ^ )];
|
||||
];
|
||||
|
||||
Mode(9, [1,2,3,4,5,5,5123,2,3])
|
||||
Loading…
Add table
Add a link
Reference in a new issue