Data update
This commit is contained in:
parent
4bb20c9b71
commit
cbaf4c4b64
12390 changed files with 318560 additions and 27248 deletions
|
|
@ -0,0 +1,18 @@
|
|||
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;
|
||||
|
|
@ -0,0 +1,27 @@
|
|||
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.
|
||||
|
|
@ -0,0 +1,70 @@
|
|||
>>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.
|
||||
|
|
@ -0,0 +1,30 @@
|
|||
(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) #'>)
|
||||
|
|
@ -0,0 +1,22 @@
|
|||
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})
|
||||
|
|
@ -0,0 +1,33 @@
|
|||
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);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,19 @@
|
|||
local function insertion_sort(a)
|
||||
for i = 2, #a do
|
||||
local v = a[i]
|
||||
local j = i - 1
|
||||
while j >= 1 and a[j] > v do
|
||||
a[j + 1] = a[j]
|
||||
j -= 1
|
||||
end
|
||||
a[j + 1] = v
|
||||
end
|
||||
end
|
||||
|
||||
local array = { {4, 65, 2, -31, 0, 99, 2, 83, 782, 1}, {7, 5, 2, 6, 1, 4, 2, 6, 3} }
|
||||
for array as a do
|
||||
print($"Before: \{{a:concat(", ")}}")
|
||||
insertion_sort(a)
|
||||
print($"After : \{{a:concat(", ")}}")
|
||||
print()
|
||||
end
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
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 ","
|
||||
|
|
@ -0,0 +1,143 @@
|
|||
# riscv assembly raspberry pico2 rp2350
|
||||
# program insertionsort.s
|
||||
# connexion putty com3
|
||||
/*********************************************/
|
||||
/* CONSTANTES */
|
||||
/********************************************/
|
||||
/* for this file see risc-v task include a file */
|
||||
.include "../../constantesRiscv.inc"
|
||||
|
||||
|
||||
|
||||
/*******************************************/
|
||||
/* INITIALED DATAS */
|
||||
/*******************************************/
|
||||
.data
|
||||
szMessStart: .asciz "Program riscv start.\r\n"
|
||||
szMessEnd: .asciz "\nProgram end OK.\r\n"
|
||||
szCariageReturn: .asciz "\r\n"
|
||||
|
||||
szLibSort: .asciz "\nAfter sort\n"
|
||||
szSpace: .asciz " "
|
||||
|
||||
.align 2
|
||||
tabNumber: .int 5,7,8,3,2,9,1,4,6
|
||||
.equ NBTABNUMBER1, . - tabNumber
|
||||
.equ NBTABNUMBER, NBTABNUMBER1 / 4 # compute items number
|
||||
|
||||
/*******************************************/
|
||||
/* UNINITIALED DATA */
|
||||
/*******************************************/
|
||||
.bss
|
||||
.align 2
|
||||
sConvArea: .skip 24
|
||||
|
||||
/**********************************************/
|
||||
/* SECTION CODE */
|
||||
/**********************************************/
|
||||
.text
|
||||
.global main
|
||||
|
||||
main:
|
||||
call stdio_init_all # général init
|
||||
1: # start loop connexion
|
||||
li a0,0 # raz argument register
|
||||
call tud_cdc_n_connected # waiting for USB connection
|
||||
beqz a0,1b # return code = zero ?
|
||||
|
||||
la a0,szMessStart # message address
|
||||
call writeString # display message
|
||||
|
||||
la s0,tabNumber # number array address
|
||||
li s1,0
|
||||
li s2,NBTABNUMBER
|
||||
2: # item loop
|
||||
sh2add t3,s1,s0 # compute item address
|
||||
lw a0,(t3)
|
||||
call displayResultD
|
||||
add s1,s1,1
|
||||
blt s1,s2,2b
|
||||
la a0,szCariageReturn
|
||||
call writeString
|
||||
mv a0,s0 # number array address
|
||||
li a1,0 # first item
|
||||
mv a2,s2 # item size
|
||||
call insertionSort # sort
|
||||
|
||||
la a0,szLibSort
|
||||
call writeString
|
||||
|
||||
li s1,0
|
||||
3: # item loop
|
||||
sh2add t3,s1,s0 # compute item address
|
||||
lw a0,(t3)
|
||||
call displayResultD
|
||||
add s1,s1,1
|
||||
blt s1,s2,3b
|
||||
la a0,szCariageReturn
|
||||
call writeString
|
||||
la a0,szMessEnd
|
||||
call writeString
|
||||
call getchar
|
||||
100: # final loop
|
||||
j 100b
|
||||
/**********************************************/
|
||||
/* display Result décimal */
|
||||
/**********************************************/
|
||||
/* a0 value */
|
||||
.equ LGZONECONV, 20
|
||||
displayResultD:
|
||||
addi sp, sp, -4 # reserve stack
|
||||
sw ra, 0(sp)
|
||||
la a1,sConvArea # conversion result address
|
||||
call conversion10 # binary conversion
|
||||
la a0,sConvArea # message address
|
||||
call writeString # display message
|
||||
la a0,szSpace
|
||||
call writeString
|
||||
100:
|
||||
lw ra, 0(sp)
|
||||
addi sp, sp, 4
|
||||
ret
|
||||
|
||||
|
||||
/******************************************************************/
|
||||
/* insertion sort */
|
||||
/******************************************************************/
|
||||
/* a0 contains array address */
|
||||
/* a1 contains the first element */
|
||||
/* a2 contains the number of element */
|
||||
insertionSort:
|
||||
addi sp, sp, -4 # reserve stack
|
||||
sw ra, 0(sp) # save registers
|
||||
addi t1,a1,1 # start index i
|
||||
1: # start loop
|
||||
sh2add t2,t1,a0
|
||||
lw t3,(t2) # load value A[i]
|
||||
addi t5,t1,-1 # index j
|
||||
2:
|
||||
sh2add t2,t5,a0
|
||||
lw t6,(t2) # load value A[j]
|
||||
ble t6,t3,3f # compare value A[i] and A[j]
|
||||
|
||||
addi t5,t5,1 # increment index j
|
||||
sh2add t2,t5,a0
|
||||
sw t6,(t2) # store value A[j+1]
|
||||
|
||||
addi t5,t5,-2 # j = i - 1
|
||||
bge t5,a1,2b # loop if j >= first item
|
||||
3:
|
||||
addi t5,t5,1
|
||||
sh2add t2,t5,a0
|
||||
sw t3,(t2) # store value A[i] in A[j+1]
|
||||
addi t1,t1,1 # increment index i
|
||||
blt t1,a2,1b # end ?
|
||||
100:
|
||||
lw ra, 0(sp)
|
||||
addi sp, sp, 4
|
||||
ret
|
||||
/************************************/
|
||||
/* file include Fonctions */
|
||||
/***********************************/
|
||||
/* for this file see risc-v task include a file */
|
||||
.include "../../includeFunctions.s"
|
||||
|
|
@ -0,0 +1,39 @@
|
|||
; 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]
|
||||
|
|
@ -0,0 +1,36 @@
|
|||
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
|
||||
Loading…
Add table
Add a link
Reference in a new issue