Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
50
Task/Averages-Mode/Objeck/averages-mode.objeck
Normal file
50
Task/Averages-Mode/Objeck/averages-mode.objeck
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
use Collection;
|
||||
|
||||
class Mode {
|
||||
function : Main(args : String[]) ~ Nil {
|
||||
Print(Mode([1, 3, 6, 6, 6, 6, 7, 7, 12, 12, 17]));
|
||||
Print(Mode([1, 2, 4, 4, 1]));
|
||||
}
|
||||
|
||||
function : Mode(coll : Int[]) ~ IntVector {
|
||||
seen := IntMap->New();
|
||||
max := 0;
|
||||
maxElems := IntVector->New();
|
||||
|
||||
each(i : coll) {
|
||||
value := coll[i];
|
||||
|
||||
featched := seen->Find(value)->As(IntHolder);
|
||||
if(featched <> Nil) {
|
||||
seen->Remove(value);
|
||||
seen->Insert(value, IntHolder->New(featched->Get() + 1));
|
||||
}
|
||||
else {
|
||||
seen->Insert(value, IntHolder->New(1));
|
||||
};
|
||||
|
||||
featched := seen->Find(value)->As(IntHolder);
|
||||
if(featched->Get() > max) {
|
||||
max := featched->Get();
|
||||
maxElems->Empty();
|
||||
maxElems->AddBack(value);
|
||||
}
|
||||
else if(featched->Get() = max) {
|
||||
maxElems->AddBack(value);
|
||||
};
|
||||
};
|
||||
|
||||
return maxElems;
|
||||
}
|
||||
|
||||
function : Print(out : IntVector) ~ Nil {
|
||||
'['->Print();
|
||||
each(i : out) {
|
||||
out->Get(i)->Print();
|
||||
if(i + 1 < out->Size()) {
|
||||
", "->Print();
|
||||
};
|
||||
};
|
||||
']'->PrintLine();
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue