Data update
This commit is contained in:
parent
5150844a7d
commit
4bb20c9b71
7735 changed files with 38060 additions and 199180 deletions
|
|
@ -1,49 +0,0 @@
|
|||
with Ada.Text_Io; use Ada.Text_Io;
|
||||
with Ada.Numerics; use Ada.Numerics;
|
||||
with Ada.Numerics.Float_Random; use Ada.Numerics.Float_Random;
|
||||
|
||||
procedure Counting_Sort is
|
||||
type Data is array (Integer range <>) of Natural;
|
||||
procedure Sort(Item : in out Data) is
|
||||
minValue, maxValue: Natural;
|
||||
begin
|
||||
minValue := Item(Item'First); maxValue := Item(Item'First);
|
||||
for I in Item'Range loop
|
||||
if Item(I) < minValue then minValue := Item(I); end if;
|
||||
if Item(I) > maxValue then maxValue := Item(I); end if;
|
||||
end loop;
|
||||
declare
|
||||
Count : Data(minValue .. maxValue);
|
||||
itemPos : Integer range Item'First - 1 .. Item'Last;
|
||||
begin
|
||||
for I in Count'Range loop
|
||||
Count(I) := 0;
|
||||
end loop;
|
||||
for I in Item'Range loop
|
||||
Count(Item(I)) := Count(Item(I)) + 1;
|
||||
end loop;
|
||||
itemPos := 0;
|
||||
for I in Count'Range loop
|
||||
for J in 1..Count(I) loop
|
||||
itemPos := itemPos + 1;
|
||||
Item(itemPos) := I;
|
||||
end loop;
|
||||
end loop;
|
||||
end;
|
||||
end Sort;
|
||||
Stuff : Data(1..30);
|
||||
Seed : Generator;
|
||||
begin
|
||||
Put("Before: ");
|
||||
for I in Stuff'Range loop
|
||||
Stuff(I) := Integer( Float'Truncation( Random( seed ) * 100.0 ) );
|
||||
Put(Natural'Image(Stuff(I)));
|
||||
end loop;
|
||||
New_Line;
|
||||
Sort(Stuff);
|
||||
Put("After : ");
|
||||
for I in Stuff'range loop
|
||||
Put(Natural'Image(Stuff(I)));
|
||||
end loop;
|
||||
New_Line;
|
||||
end Counting_Sort;
|
||||
|
|
@ -28,10 +28,10 @@ extension op
|
|||
}
|
||||
}
|
||||
|
||||
public program()
|
||||
public Program()
|
||||
{
|
||||
var list := new Range(0, 10).selectBy::(i => randomGenerator.nextInt(10)).toArray();
|
||||
var list := new Range(0, 10).selectBy::(i => Random.nextInt(10)).toArray();
|
||||
|
||||
console.printLine("before:", list.asEnumerable());
|
||||
console.printLine("after :", list.countingSort().asEnumerable())
|
||||
Console.printLine("before:", list.asEnumerable());
|
||||
Console.printLine("after :", list.countingSort().asEnumerable())
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,33 +0,0 @@
|
|||
class CountingSort {
|
||||
public static function sort(arr:Array<Int>) {
|
||||
var min = arr[0], max = arr[0];
|
||||
for (i in 1...arr.length) {
|
||||
if (arr[i] < min)
|
||||
min = arr[i];
|
||||
else if (arr[i] > max)
|
||||
max = arr[i];
|
||||
}
|
||||
|
||||
var range = max - min + 1;
|
||||
var count = new Array<Int>();
|
||||
count.resize(range * arr.length);
|
||||
|
||||
for (i in 0...range) count[i] = 0;
|
||||
for (i in 0...arr.length) count[arr[i] - min]++;
|
||||
|
||||
var z = 0;
|
||||
for (i in min...(max + 1)) {
|
||||
for (j in 0...count[i - min])
|
||||
arr[z++] = i;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class Main {
|
||||
static function main() {
|
||||
var integerArray = [1, 10, 2, 5, -1, 5, -19, 4, 23, 0];
|
||||
Sys.println('Unsorted Integers: ' + integerArray);
|
||||
CountingSort.sort(integerArray);
|
||||
Sys.println('Sorted Integers: ' + integerArray);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,22 +1,15 @@
|
|||
(phixonline)-->
|
||||
<span style="color: #008080;">with</span> <span style="color: #008080;">javascript_semantics</span>
|
||||
with javascript_semantics
|
||||
|
||||
<span style="color: #008080;">function</span> <span style="color: #000000;">countingSort</span><span style="color: #0000FF;">(</span><span style="color: #004080;">sequence</span> <span style="color: #000000;">array</span><span style="color: #0000FF;">,</span> <span style="color: #004080;">integer</span> <span style="color: #000000;">mina</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">maxa</span><span style="color: #0000FF;">)</span>
|
||||
<span style="color: #004080;">sequence</span> <span style="color: #000000;">count</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">repeat</span><span style="color: #0000FF;">(</span><span style="color: #000000;">0</span><span style="color: #0000FF;">,</span><span style="color: #000000;">maxa</span><span style="color: #0000FF;">-</span><span style="color: #000000;">mina</span><span style="color: #0000FF;">+</span><span style="color: #000000;">1</span><span style="color: #0000FF;">)</span>
|
||||
<span style="color: #000000;">array</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">deep_copy</span><span style="color: #0000FF;">(</span><span style="color: #000000;">array</span><span style="color: #0000FF;">)</span>
|
||||
<span style="color: #008080;">for</span> <span style="color: #000000;">i</span><span style="color: #0000FF;">=</span><span style="color: #000000;">1</span> <span style="color: #008080;">to</span> <span style="color: #7060A8;">length</span><span style="color: #0000FF;">(</span><span style="color: #000000;">array</span><span style="color: #0000FF;">)</span> <span style="color: #008080;">do</span>
|
||||
<span style="color: #000000;">count</span><span style="color: #0000FF;">[</span><span style="color: #000000;">array</span><span style="color: #0000FF;">[</span><span style="color: #000000;">i</span><span style="color: #0000FF;">]-</span><span style="color: #000000;">mina</span><span style="color: #0000FF;">+</span><span style="color: #000000;">1</span><span style="color: #0000FF;">]</span> <span style="color: #0000FF;">+=</span> <span style="color: #000000;">1</span>
|
||||
<span style="color: #008080;">end</span> <span style="color: #008080;">for</span>
|
||||
<span style="color: #004080;">integer</span> <span style="color: #000000;">z</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">1</span>
|
||||
<span style="color: #008080;">for</span> <span style="color: #000000;">i</span><span style="color: #0000FF;">=</span><span style="color: #000000;">mina</span> <span style="color: #008080;">to</span> <span style="color: #000000;">maxa</span> <span style="color: #008080;">do</span>
|
||||
<span style="color: #008080;">for</span> <span style="color: #000000;">j</span><span style="color: #0000FF;">=</span><span style="color: #000000;">1</span> <span style="color: #008080;">to</span> <span style="color: #000000;">count</span><span style="color: #0000FF;">[</span><span style="color: #000000;">i</span><span style="color: #0000FF;">-</span><span style="color: #000000;">mina</span><span style="color: #0000FF;">+</span><span style="color: #000000;">1</span><span style="color: #0000FF;">]</span> <span style="color: #008080;">do</span>
|
||||
<span style="color: #000000;">array</span><span style="color: #0000FF;">[</span><span style="color: #000000;">z</span><span style="color: #0000FF;">]</span> <span style="color: #0000FF;">:=</span> <span style="color: #000000;">i</span>
|
||||
<span style="color: #000000;">z</span> <span style="color: #0000FF;">+=</span> <span style="color: #000000;">1</span>
|
||||
<span style="color: #008080;">end</span> <span style="color: #008080;">for</span>
|
||||
<span style="color: #008080;">end</span> <span style="color: #008080;">for</span>
|
||||
<span style="color: #008080;">return</span> <span style="color: #000000;">array</span>
|
||||
<span style="color: #008080;">end</span> <span style="color: #008080;">function</span>
|
||||
function counting_sort(sequence s, integer mine, maxe)
|
||||
sequence count = repeat(0,maxe-mine+1), res = {}
|
||||
for e in s do
|
||||
count[e-mine+1] += 1
|
||||
end for
|
||||
for i,c in count do
|
||||
res &= repeat(i+mine-1,c)
|
||||
end for
|
||||
return res
|
||||
end function
|
||||
|
||||
<span style="color: #004080;">sequence</span> <span style="color: #000000;">s</span> <span style="color: #0000FF;">=</span> <span style="color: #0000FF;">{</span><span style="color: #000000;">5</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">3</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">1</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">7</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">4</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">1</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">1</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">20</span><span style="color: #0000FF;">}</span>
|
||||
<span style="color: #0000FF;">?</span><span style="color: #000000;">countingSort</span><span style="color: #0000FF;">(</span><span style="color: #000000;">s</span><span style="color: #0000FF;">,</span><span style="color: #7060A8;">min</span><span style="color: #0000FF;">(</span><span style="color: #000000;">s</span><span style="color: #0000FF;">),</span><span style="color: #7060A8;">max</span><span style="color: #0000FF;">(</span><span style="color: #000000;">s</span><span style="color: #0000FF;">))</span>
|
||||
<!--
|
||||
sequence s = {5, 3, 1, 7, 4, 1, 1, 20}
|
||||
?counting_sort(s,min(s),max(s))
|
||||
|
|
|
|||
|
|
@ -1,21 +0,0 @@
|
|||
function countingSort($array) {
|
||||
$minmax = $array | Measure-Object -Minimum -Maximum
|
||||
$min, $max = $minmax.Minimum, $minmax.Maximum
|
||||
$count = @(0) * ($max - $min + 1)
|
||||
foreach ($number in $array) {
|
||||
$count[$number - $min] = $count[$number - $min] + 1
|
||||
}
|
||||
$z = 0
|
||||
foreach ($i in $min..$max) {
|
||||
while (0 -lt $count[$i - $min]) {
|
||||
$array[$z] = $i
|
||||
$z = $z+1
|
||||
$count[$i - $min] = $count[$i - $min] - 1
|
||||
}
|
||||
}
|
||||
$array
|
||||
}
|
||||
|
||||
$array = foreach ($i in 1..50) {Get-Random -Minimum 0 -Maximum 26}
|
||||
"$array"
|
||||
"$(countingSort $array)"
|
||||
|
|
@ -1,42 +0,0 @@
|
|||
function findMax( a )
|
||||
dim num
|
||||
dim max
|
||||
max = 0
|
||||
for each num in a
|
||||
if num > max then max = num
|
||||
next
|
||||
findMax = max
|
||||
end function
|
||||
|
||||
function findMin( a )
|
||||
dim num
|
||||
dim min
|
||||
min = 0
|
||||
for each num in a
|
||||
if num < min then min = num
|
||||
next
|
||||
findMin = min
|
||||
end function
|
||||
|
||||
'the function returns the sorted array, but the fact is that VBScript passes the array by reference anyway
|
||||
function countingSort( a )
|
||||
dim count()
|
||||
dim min, max
|
||||
min = findMin(a)
|
||||
max = findMax(a)
|
||||
redim count( max - min + 1 )
|
||||
dim i
|
||||
dim z
|
||||
for i = 0 to ubound( a )
|
||||
count( a(i) - min ) = count( a( i ) - min ) + 1
|
||||
next
|
||||
z = 0
|
||||
for i = min to max
|
||||
while count( i - min) > 0
|
||||
a(z) = i
|
||||
z = z + 1
|
||||
count( i - min ) = count( i - min ) - 1
|
||||
wend
|
||||
next
|
||||
countingSort = a
|
||||
end function
|
||||
|
|
@ -1,5 +0,0 @@
|
|||
dim a
|
||||
a = array(300, 1, -2, 3, -4, 5, -6, 7, -8, 100, 11 )
|
||||
wscript.echo join( a, ", " )
|
||||
countingSort a
|
||||
wscript.echo join( a, ", " )
|
||||
Loading…
Add table
Add a link
Reference in a new issue