Initial data commit

This commit is contained in:
Ingy döt Net 2023-07-01 11:58:00 -04:00
parent 72d218235f
commit f23f22d71c
199087 changed files with 3378941 additions and 0 deletions

View file

@ -0,0 +1,37 @@
import extensions;
import system'routines;
extension op
{
countingSort()
= self.clone().countingSort(self.MinimalMember, self.MaximalMember);
countingSort(int min, int max)
{
int[] count := new int[](max - min + 1);
int z := 0;
count.populate:(int i => 0);
for(int i := 0, i < self.Length, i += 1) { count[self[i] - min] := count[self[i] - min] + 1 };
for(int i := min, i <= max, i += 1)
{
while (count[i - min] > 0)
{
self[z] := i;
z += 1;
count[i - min] := count[i - min] - 1
}
}
}
}
public program()
{
var list := new Range(0, 10).selectBy:(i => randomGenerator.eval(10)).toArray();
console.printLine("before:", list.asEnumerable());
console.printLine("after :", list.countingSort().asEnumerable())
}