September Morn Update
This commit is contained in:
parent
4e2d22a71d
commit
aac6731f2c
6856 changed files with 141342 additions and 21127 deletions
|
|
@ -1,37 +1,37 @@
|
|||
import extensions.
|
||||
import system'routines.
|
||||
import extensions;
|
||||
import system'routines;
|
||||
|
||||
extension $op
|
||||
extension op
|
||||
{
|
||||
countingSort
|
||||
= self clone; countingSort(self minimalMember, self maximalMember).
|
||||
countingSort()
|
||||
= self.clone().countingSort(self.MinimalMember, self.MaximalMember);
|
||||
|
||||
countingSort int:min int:max
|
||||
[
|
||||
array<int> count := int<>(max - min + 1).
|
||||
int z := 0.
|
||||
countingSort(int min, int max)
|
||||
{
|
||||
int[] count := new int[](max - min + 1);
|
||||
int z := 0;
|
||||
|
||||
count populate(:i)<int>(0).
|
||||
count.populate:(int i => 0);
|
||||
|
||||
0 till(self length) do(:i) [ count[self[i] - min] += 1 ].
|
||||
for(int i := 0, i < self.Length, i += 1) { count[self[i] - min] := count[self[i] - min] + 1 };
|
||||
|
||||
min to:max do(:i)
|
||||
[
|
||||
for(int i := min, i <= max, i += 1)
|
||||
{
|
||||
while (count[i - min] > 0)
|
||||
[
|
||||
self[z] := i.
|
||||
z += 1.
|
||||
{
|
||||
self[z] := i;
|
||||
z += 1;
|
||||
|
||||
count[i - min] -= 1.
|
||||
]
|
||||
]
|
||||
]
|
||||
count[i - min] := count[i - min] - 1
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
program =
|
||||
[
|
||||
var list := 0 to:10 repeat(:i)(randomGenerator eval(10)); toArray.
|
||||
public program()
|
||||
{
|
||||
var list := new Range(0, 10).selectBy:(i => randomGenerator.eval(10)).toArray();
|
||||
|
||||
console printLine("before:", list).
|
||||
console printLine("after :", list countingSort).
|
||||
].
|
||||
console.printLine("before:", list.asEnumerable());
|
||||
console.printLine("after :", list.countingSort().asEnumerable())
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue