Data update

This commit is contained in:
Ingy döt Net 2026-04-30 12:34:36 -04:00
parent 4bb20c9b71
commit cbaf4c4b64
12390 changed files with 318560 additions and 27248 deletions

View file

@ -0,0 +1,37 @@
with Ada.Text_Io; use Ada.Text_Io;
procedure Cocktail_Sort_Test is
procedure Cocktail_Sort (Item : in out String) is
procedure Swap(Left, Right : in out Character) is
Temp : Character := Left;
begin
Left := Right;
Right := Temp;
end Swap;
Swapped : Boolean := False;
begin
loop
for I in 1..Item'Last - 1 loop
if Item(I) > Item(I + 1) then
Swap(Item(I), Item(I + 1));
Swapped := True;
end if;
end loop;
if not Swapped then
for I in reverse 1..Item'Last - 1 loop
if Item(I) > Item(I + 1) then
Swap(Item(I), Item(I + 1));
Swapped := True;
end if;
end loop;
end if;
exit when not Swapped;
Swapped := False;
end loop;
end Cocktail_Sort;
Data : String := "big fjords vex quick waltz nymph";
begin
Put_Line(Data);
Cocktail_Sort(Data);
Put_Line(Data);
end Cocktail_Sort_Test;

View file

@ -0,0 +1,38 @@
C-SORT SECTION.
C-000.
DISPLAY "SORT STARTING".
MOVE 2 TO WC-START
MOVE WC-SIZE TO WC-END.
MOVE 1 TO WC-DIRECTION
WC-LAST-CHANGE.
PERFORM E-SHAKER UNTIL WC-END * WC-DIRECTION <
WC-START * WC-DIRECTION.
DISPLAY "SORT FINISHED".
C-999.
EXIT.
E-SHAKER SECTION.
E-000.
PERFORM F-PASS VARYING WB-IX-1 FROM WC-START BY WC-DIRECTION
UNTIL WB-IX-1 = WC-END + WC-DIRECTION.
MOVE WC-START TO WC-END.
SUBTRACT WC-DIRECTION FROM WC-LAST-CHANGE GIVING WC-START.
MULTIPLY WC-DIRECTION BY -1 GIVING WC-DIRECTION.
E-999.
EXIT.
F-PASS SECTION.
F-000.
IF WB-ENTRY(WB-IX-1 - 1) > WB-ENTRY(WB-IX-1)
SET WC-LAST-CHANGE TO WB-IX-1
MOVE WB-ENTRY(WB-IX-1 - 1) TO WC-TEMP
MOVE WB-ENTRY(WB-IX-1) TO WB-ENTRY(WB-IX-1 - 1)
MOVE WC-TEMP TO WB-ENTRY(WB-IX-1).
F-999.
EXIT.

View file

@ -0,0 +1,25 @@
function cocktail_sort(sequence s)
integer swapped, d
object temp
sequence fromto
fromto = {1,length(s)-1}
swapped = 1
d = 1
while swapped do
swapped = 0
for i = fromto[(1-d)/2+1] to fromto[(1+d)/2+1] by d do
if compare(s[i],s[i+1])>0 then
temp = s[i]
s[i] = s[i+1]
s[i+1] = temp
swapped = 1
end if
end for
d = -d
end while
return s
end function
constant s = rand(repeat(1000,10))
? s
? cocktail_sort(s)

View file

@ -0,0 +1,49 @@
class CocktailSort {
@:generic
public static function sort<T>(arr:Array<T>) {
var swapped = false;
do {
swapped = false;
for (i in 0...(arr.length - 1)) {
if (Reflect.compare(arr[i], arr[i + 1]) > 0) {
var temp = arr[i];
arr[i] = arr[i + 1];
arr[i + 1] = temp;
swapped = true;
}
}
if (!swapped) break;
swapped = false;
var i = arr.length - 2;
while (i >= 0) {
if (Reflect.compare(arr[i], arr[i + 1]) > 0) {
var temp = arr[i];
arr[i] = arr[i + 1];
arr[i + 1] = temp;
swapped = true;
}
i--;
}
} while (swapped);
}
}
class Main {
static function main() {
var integerArray = [1, 10, 2, 5, -1, 5, -19, 4, 23, 0];
var floatArray = [1.0, -3.2, 5.2, 10.8, -5.7, 7.3,
3.5, 0.0, -4.1, -9.5];
var stringArray = ['We', 'hold', 'these', 'truths', 'to',
'be', 'self-evident', 'that', 'all',
'men', 'are', 'created', 'equal'];
Sys.println('Unsorted Integers: ' + integerArray);
CocktailSort.sort(integerArray);
Sys.println('Sorted Integers: ' + integerArray);
Sys.println('Unsorted Floats: ' + floatArray);
CocktailSort.sort(floatArray);
Sys.println('Sorted Floats: ' + floatArray);
Sys.println('Unsorted Strings: ' + stringArray);
CocktailSort.sort(stringArray);
Sys.println('Sorted Strings: ' + stringArray);
}
}

View file

@ -0,0 +1,28 @@
local function cocktail_sort(a)
local last = #a
while true do
local swapped = false
for i = 1, last - 1 do
if a[i] > a[i + 1] then
a[i], a[i + 1] = a[i + 1], a[i]
swapped = true
end
end
if !swapped then return end
swapped = false
if last >= 1 then
for i = last - 1, 1, -1 do
if a[i] > a[i + 1] then
a[i], a[i + 1] = a[i + 1], a[i]
swapped = true
end
end
end
if !swapped then return end
end
end
local a = {170, 45, 75, -90, -802, 24, 2, 66}
print($"Before: \{{a:concat(", ")}}")
cocktail_sort(a)
print($"After : \{{a:concat(", ")}}")

View file

@ -0,0 +1,32 @@
function CocktailSort ($a) {
$l = $a.Length
$m = 0
if( $l -gt 1 )
{
$hasChanged = $true
:outer while ($hasChanged) {
$hasChanged = $false
$l--
for ($i = $m; $i -lt $l; $i++) {
if ($a[$i] -gt $a[$i+1]) {
$a[$i], $a[$i+1] = $a[$i+1], $a[$i]
$hasChanged = $true
}
}
if(-not $hasChanged) {
break outer
}
$hasChanged = $false
for ($i = $l; $i -gt $m; $i--) {
if ($a[$i-1] -gt $a[$i]) {
$a[$i-1], $a[$i] = $a[$i], $a[$i-1]
$hasChanged = $true
}
}
$m++
}
}
$a
}
$l = 10; CocktailSort ( 1..$l | ForEach-Object { $Rand = New-Object Random }{ $Rand.Next( -( $l - 1 ), $l - 1 ) } )

View file

@ -0,0 +1,30 @@
function cocktailSort( byval a )
dim swapped
dim i
do
swapped = false
for i = 0 to ubound( a ) - 1
if a(i) > a(i+1) then
swap a(i), a(i+1)
swapped = true
end if
next
if not swapped then exit do
swapped = false
for i = ubound( a ) - 1 to 0 step -1
if a(i) > a( i+1) then
swap a(i), a(i+1)
swapped = true
end if
next
if not swapped then exit do
loop
cocktailSort = a
end function
sub swap( byref a, byref b)
dim tmp
tmp = a
a = b
b = tmp
end sub

View file

@ -0,0 +1,7 @@
dim a
a = array( "portcullis", "redoubt", "palissade", "turret", "collins", "the parapet", "the quarterdeck")
wscript.echo join( a, ", ")
dim b
b = cocktailSort( a )
wscript.echo join( b, ", ")