September 2017 Update

This commit is contained in:
Ingy döt Net 2017-09-23 10:01:46 +02:00
parent bba7bfd280
commit ba8067c3b7
14570 changed files with 153136 additions and 63871 deletions

View file

@ -0,0 +1,16 @@
-module(solution).
-import(lists,[delete/2,max/1]).
-compile(export_all).
selection_sort([],Sort)-> Sort;
selection_sort(Ar,Sort)->
M=max(Ar),
Ad=delete(M,Ar),
selection_sort(Ad,[M|Sort]).
print_array([])->ok;
print_array([H|T])->
io:format("~p~n",[H]),
print_array(T).
main()->
Ans=selection_sort([1,5,7,8,4,10],[]),
print_array(Ans).

View file

@ -0,0 +1,53 @@
/*REXX ****************************************************************
* program sorts an array using the selection-sort method.
* derived from REXX solution
* Note that ooRexx can process Elements of the stem argument (Use Arg)
* 06.10.2010 Walter Pachl
**********************************************************************/
call generate /*generate the array elements. */
call show 'before sort' /*show the before array elements,*/
call selectionSort x. /*invoke the selection sort. */
call show 'after sort' /*show the after array elements.*/
exit /*stick a fork in it, we're done.*/
selectionSort: Procedure
Use Arg s. /* gain access to the argument */
do j=1 To s.0-1
t=s.j;
p=j;
do k=j+1 to s.0
if s.k<t then do;
t=s.k;
p=k;
end
end
if p=j then
iterate
t=s.j;
s.j=s.p;
s.p=t
end
return
show:
Parse Arg heading
Say heading
Do i=1 To x.0
Say i' 'x.i
End
say copies('-',79)
Return
return
generate:
x.1='---The seven hills of Rome:---'
x.2='=============================='
x.3='Caelian'
x.4='Palatine'
x.5='Capitoline'
x.6='Virminal'
x.7='Esquiline'
x.8='Quirinal'
x.9='Aventine'
x.0=9
return

View file

@ -0,0 +1,29 @@
fn selection_sort(array: &mut [i32]) {
let mut min;
for i in 0..array.len() {
min = i;
for j in (i+1)..array.len() {
if array[j] < array[min] {
min = j;
}
}
let tmp = array[i];
array[i] = array[min];
array[min] = tmp;
}
}
fn main() {
let mut array = [ 9, 4, 8, 3, -5, 2, 1, 6 ];
println!("The initial array is {:?}", array);
selection_sort(&mut array);
println!(" The sorted array is {:?}", array);
}

View file

@ -0,0 +1,9 @@
fcn selectionSort(list){ // sort a list of ints
copy,r:=list.copy(),List();
while(copy){
min,idx:=(0).min(copy), copy.find(min);
r.append(min);
copy.del(idx);
}
r
}

View file

@ -0,0 +1 @@
selectionSort(List(28, 44, 46, 24, 19, -5, 2, 17, 11, 25, 4)).println();