Data update

This commit is contained in:
Ingy döt Net 2026-02-01 16:33:20 -08:00
parent 5150844a7d
commit 4bb20c9b71
7735 changed files with 38060 additions and 199180 deletions

View file

@ -1,18 +0,0 @@
type Data_Array is array(Natural range <>) of Integer;
procedure Insertion_Sort(Item : in out Data_Array) is
First : Natural := Item'First;
Last : Natural := Item'Last;
Value : Integer;
J : Integer;
begin
for I in (First + 1)..Last loop
Value := Item(I);
J := I - 1;
while J in Item'range and then Item(J) > Value loop
Item(J + 1) := Item(J);
J := J - 1;
end loop;
Item(J + 1) := Value;
end loop;
end Insertion_Sort;

View file

@ -1,27 +0,0 @@
C-PROCESS SECTION.
PERFORM E-INSERTION VARYING WB-IX-1 FROM 1 BY 1
UNTIL WB-IX-1 > WC-SIZE.
...
E-INSERTION SECTION.
E-000.
MOVE WB-ENTRY(WB-IX-1) TO WC-TEMP.
SET WB-IX-2 TO WB-IX-1.
PERFORM F-PASS UNTIL WB-IX-2 NOT > 1 OR
WC-TEMP NOT < WB-ENTRY(WB-IX-2 - 1).
IF WB-IX-1 NOT = WB-IX-2
MOVE WC-TEMP TO WB-ENTRY(WB-IX-2).
E-999.
EXIT.
F-PASS SECTION.
F-000.
MOVE WB-ENTRY(WB-IX-2 - 1) TO WB-ENTRY(WB-IX-2).
SET WB-IX-2 DOWN BY 1.
F-999.
EXIT.

View file

@ -1,70 +0,0 @@
>>SOURCE FORMAT FREE
*> This code is dedicated to the public domain
*> This is GNUCOBOL 2.0
identification division.
program-id. insertionsort.
environment division.
configuration section.
repository. function all intrinsic.
data division.
working-storage section.
01 filler.
03 a pic 99.
03 a-lim pic 99 value 10.
03 array occurs 10 pic 99.
01 filler.
03 s pic 99.
03 o pic 99.
03 o1 pic 99.
03 sorted-len pic 99.
03 sorted-lim pic 99 value 10.
03 sorted-array occurs 10 pic 99.
procedure division.
start-insertionsort.
*> fill the array
compute a = random(seconds-past-midnight)
perform varying a from 1 by 1 until a > a-lim
compute array(a) = random() * 100
end-perform
*> display the array
perform varying a from 1 by 1 until a > a-lim
display space array(a) with no advancing
end-perform
display space 'initial array'
*> sort the array
move 0 to sorted-len
perform varying a from 1 by 1 until a > a-lim
*> find the insertion point
perform varying s from 1 by 1
until s > sorted-len
or array(a) <= sorted-array(s)
continue
end-perform
*>open the insertion point
perform varying o from sorted-len by -1
until o < s
compute o1 = o + 1
move sorted-array(o) to sorted-array(o1)
end-perform
*> move the array-entry to the insertion point
move array(a) to sorted-array(s)
add 1 to sorted-len
end-perform
*> display the sorted array
perform varying s from 1 by 1 until s > sorted-lim
display space sorted-array(s) with no advancing
end-perform
display space 'sorted array'
stop run
.
end program insertionsort.

View file

@ -24,10 +24,10 @@ extension op
}
}
public program()
public Program()
{
var list := new int[]{3, 9, 4, 6, 8, 1, 7, 2, 5};
console.printLine("before:", list.asEnumerable());
console.printLine("after :", list.insertionSort().asEnumerable());
Console.printLine("before:", list.asEnumerable());
Console.printLine("after :", list.insertionSort().asEnumerable());
}

View file

@ -1,30 +0,0 @@
(defun min-or-max-of-a-list (numbers comparator)
"Return minimum or maximum of NUMBERS using COMPARATOR."
(let ((extremum (car numbers)))
(dolist (n (cdr numbers))
(when (funcall comparator n extremum)
(setq extremum n)))
extremum))
(defun remove-number-from-list (numbers n)
"Return NUMBERS without N.
If n is present twice or more, it will be removed only once."
(let (result)
(while numbers
(let ((number (pop numbers)))
(if (= number n)
(while numbers
(push (pop numbers) result))
(push number result))))
(nreverse result)))
(defun insertion-sort (numbers comparator)
"Return sorted list of NUMBERS using COMPARATOR."
(if numbers
(let ((extremum (min-or-max-of-a-list numbers comparator)))
(cons extremum
(insertion-sort (remove-number-from-list numbers extremum)
comparator)))
nil))
(insertion-sort '(1 2 3 9 8 7 25 12 3 2 1) #'>)

View file

@ -1,22 +0,0 @@
function insertion_sort(sequence s)
object temp
integer j
for i = 2 to length(s) do
temp = s[i]
j = i-1
while j >= 1 and compare(s[j],temp) > 0 do
s[j+1] = s[j]
j -= 1
end while
s[j+1] = temp
end for
return s
end function
include misc.e
constant s = {4, 15, "delta", 2, -31, 0, "alfa", 19, "gamma", 2, 13, "beta", 782, 1}
puts(1,"Before: ")
pretty_print(1,s,{2})
puts(1,"\nAfter: ")
pretty_print(1,insertion_sort(s),{2})

View file

@ -1,5 +1,6 @@
//
// Insertion Sort in FutureBasic
// Insertion Sort
// Using FutureBasic 7.0.34, July 2025 R.W
//
_maxDim = 99 // size of array

View file

@ -1,33 +0,0 @@
class InsertionSort {
@:generic
public static function sort<T>(arr:Array<T>) {
for (i in 1...arr.length) {
var value = arr[i];
var j = i - 1;
while (j >= 0 && Reflect.compare(arr[j], value) > 0) {
arr[j + 1] = arr[j--];
}
arr[j + 1] = value;
}
}
}
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);
InsertionSort.sort(integerArray);
Sys.println('Sorted Integers: ' + integerArray);
Sys.println('Unsorted Floats: ' + floatArray);
InsertionSort.sort(floatArray);
Sys.println('Sorted Floats: ' + floatArray);
Sys.println('Unsorted Strings: ' + stringArray);
InsertionSort.sort(stringArray);
Sys.println('Sorted Strings: ' + stringArray);
}
}

View file

@ -1,21 +1,17 @@
(phixonline)-->
<span style="color: #008080;">function</span> <span style="color: #000000;">insertion_sort</span><span style="color: #0000FF;">(</span><span style="color: #004080;">sequence</span> <span style="color: #000000;">s</span><span style="color: #0000FF;">)</span>
<span style="color: #004080;">object</span> <span style="color: #000000;">temp</span>
<span style="color: #004080;">integer</span> <span style="color: #000000;">j</span>
<span style="color: #008080;">for</span> <span style="color: #000000;">i</span><span style="color: #0000FF;">=</span><span style="color: #000000;">2</span> <span style="color: #008080;">to</span> <span style="color: #7060A8;">length</span><span style="color: #0000FF;">(</span><span style="color: #000000;">s</span><span style="color: #0000FF;">)</span> <span style="color: #008080;">do</span>
<span style="color: #000000;">temp</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">s</span><span style="color: #0000FF;">[</span><span style="color: #000000;">i</span><span style="color: #0000FF;">]</span>
<span style="color: #000000;">j</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">i</span><span style="color: #0000FF;">-</span><span style="color: #000000;">1</span>
<span style="color: #008080;">while</span> <span style="color: #000000;">j</span><span style="color: #0000FF;">>=</span><span style="color: #000000;">1</span> <span style="color: #008080;">and</span> <span style="color: #000000;">s</span><span style="color: #0000FF;">[</span><span style="color: #000000;">j</span><span style="color: #0000FF;">]></span><span style="color: #000000;">temp</span> <span style="color: #008080;">do</span>
<span style="color: #000000;">s</span><span style="color: #0000FF;">[</span><span style="color: #000000;">j</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;">s</span><span style="color: #0000FF;">[</span><span style="color: #000000;">j</span><span style="color: #0000FF;">]</span>
<span style="color: #000000;">j</span> <span style="color: #0000FF;">-=</span> <span style="color: #000000;">1</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">while</span>
<span style="color: #000000;">s</span><span style="color: #0000FF;">[</span><span style="color: #000000;">j</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;">temp</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">for</span>
<span style="color: #008080;">return</span> <span style="color: #000000;">s</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">function</span>
with javascript_semantics
function insertion_sort(sequence s)
s = deep_copy(s)
for i=2 to length(s) do
object temp = s[i]
integer j = i-1
while j>=1 and s[j]>temp do
s[j+1] = s[j]
j -= 1
end while
s[j+1] = temp
end for
return s
end function
<span style="color: #008080;">constant</span> <span style="color: #000000;">s</span> <span style="color: #0000FF;">=</span> <span style="color: #0000FF;">{</span><span style="color: #000000;">4</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">15</span><span style="color: #0000FF;">,</span> <span style="color: #008000;">"delta"</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">2</span><span style="color: #0000FF;">,</span> <span style="color: #0000FF;">-</span><span style="color: #000000;">31</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">0</span><span style="color: #0000FF;">,</span> <span style="color: #008000;">"alpha"</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">19</span><span style="color: #0000FF;">,</span> <span style="color: #008000;">"gamma"</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">2</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">13</span><span style="color: #0000FF;">,</span> <span style="color: #008000;">"beta"</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">782</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">1</span><span style="color: #0000FF;">}</span>
<span style="color: #7060A8;">puts</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"Before: "</span><span style="color: #0000FF;">)</span> <span style="color: #0000FF;">?</span><span style="color: #000000;">s</span>
<span style="color: #7060A8;">puts</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"After: "</span><span style="color: #0000FF;">)</span> <span style="color: #0000FF;">?</span><span style="color: #000000;">insertion_sort</span><span style="color: #0000FF;">(</span><span style="color: #000000;">s</span><span style="color: #0000FF;">)</span>
<!--
constant s = {4,15,"delta",2,-31,0,"alpha",19,"gamma",2,13,"beta",782,1}
printf(1,"Before: %v\n After: %v\n",{s,insertion_sort(s)})

View file

@ -1,15 +0,0 @@
function insertionSort($arr){
for($i=0;$i -lt $arr.length;$i++){
$val = $arr[$i]
$j = $i-1
while($j -ge 0 -and $arr[$j] -gt $val){
$arr[$j+1] = $arr[$j]
$j--
}
$arr[$j+1] = $val
}
}
$arr = @(4,2,1,6,9,3,8,7)
insertionSort($arr)
$arr -join ","

View file

@ -1,39 +0,0 @@
; This program works with REBOL version R2 and R3, to make it work with Red
; change the word func to function
insertion-sort: func [
a [block!]
/local i [integer!] j [integer!] n [integer!]
value [integer! string! date!]
][
i: 2
n: length? a
while [i <= n][
value: a/:i
j: i
while [ all [ 1 < j
value < a/(j - 1) ]][
a/:j: a/(j - 1)
j: j - 1
]
a/:j: value
i: i + 1
]
a
]
probe insertion-sort [4 2 1 6 9 3 8 7]
probe insertion-sort [ "---Monday's Child Is Fair of Face (by Mother Goose)---"
"Monday's child is fair of face;"
"Tuesday's child is full of grace;"
"Wednesday's child is full of woe;"
"Thursday's child has far to go;"
"Friday's child is loving and giving;"
"Saturday's child works hard for a living;"
"But the child that is born on the Sabbath day"
"Is blithe and bonny, good and gay."]
; just by adding the date! type to the local variable value the same function can sort dates.
probe insertion-sort [12-Jan-2015 11-Jan-2015 11-Jan-2016 12-Jan-2014]

View file

@ -1,36 +0,0 @@
Randomize
Dim n(9) 'nine is the upperbound.
'since VBS arrays are 0-based, it will have 10 elements.
For L = 0 to 9
n(L) = Int(Rnd * 32768)
Next
WScript.StdOut.Write "ORIGINAL : "
For L = 0 to 9
WScript.StdOut.Write n(L) & ";"
Next
InsertionSort n
WScript.StdOut.Write vbCrLf & " SORTED : "
For L = 0 to 9
WScript.StdOut.Write n(L) & ";"
Next
'the function
Sub InsertionSort(theList)
For insertionElementIndex = 1 To UBound(theList)
insertionElement = theList(insertionElementIndex)
j = insertionElementIndex - 1
Do While j >= 0
'necessary for BASICs without short-circuit evaluation
If insertionElement < theList(j) Then
theList(j + 1) = theList(j)
j = j - 1
Else
Exit Do
End If
Loop
theList(j + 1) = insertionElement
Next
End Sub