September Morn Update
This commit is contained in:
parent
4e2d22a71d
commit
aac6731f2c
6856 changed files with 141342 additions and 21127 deletions
|
|
@ -1,40 +1,41 @@
|
|||
import extensions.
|
||||
import system'routines.
|
||||
import extensions;
|
||||
import system'routines;
|
||||
|
||||
extension $op
|
||||
extension op
|
||||
{
|
||||
gnomeSort
|
||||
[
|
||||
var list := self clone.
|
||||
int i := 1.
|
||||
int j := 2.
|
||||
gnomeSort()
|
||||
{
|
||||
var list := self.clone();
|
||||
int i := 1;
|
||||
int j := 2;
|
||||
|
||||
while (i < list length)
|
||||
[
|
||||
while (i < list.Length)
|
||||
{
|
||||
if (list[i-1]<=list[i])
|
||||
[
|
||||
i := j.
|
||||
{
|
||||
i := j;
|
||||
j += 1
|
||||
];
|
||||
[
|
||||
list exchange(i-1,i).
|
||||
i -= 1.
|
||||
}
|
||||
else
|
||||
{
|
||||
list.exchange(i-1,i);
|
||||
i -= 1;
|
||||
if (i==0)
|
||||
[
|
||||
i := 1.
|
||||
{
|
||||
i := 1;
|
||||
j := 2
|
||||
]
|
||||
]
|
||||
].
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
^ list
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
program =
|
||||
[
|
||||
var list := (3, 9, 4, 6, 8, 1, 7, 2, 5).
|
||||
public program()
|
||||
{
|
||||
var list := new int[]{3, 9, 4, 6, 8, 1, 7, 2, 5};
|
||||
|
||||
console printLine("before:", list).
|
||||
console printLine("after :", list gnomeSort).
|
||||
].
|
||||
console.printLine("before:", list.asEnumerable());
|
||||
console.printLine("after :", list.gnomeSort().asEnumerable())
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
function gnomeSort(a)
|
||||
local i, j = 2, 3
|
||||
|
||||
while i < #a do
|
||||
while i <= #a do
|
||||
if a[i-1] <= a[i] then
|
||||
i = j
|
||||
j = j + 1
|
||||
|
|
|
|||
|
|
@ -6,17 +6,17 @@ call gnomeSort # /*invoke the well─known gnom
|
|||
call show ' after sort' /*display the after array elements.*/
|
||||
exit /*stick a fork in it, we're all done. */
|
||||
/*──────────────────────────────────────────────────────────────────────────────────────*/
|
||||
gen: @.=; @.1='---the seven virtues---'; @.4="Hope" ; @.7='Justice'
|
||||
@.2='======================='; @.5="Charity [LOVE]"; @.8='Prudence'
|
||||
@.3='Faith' ; @.6="Fortitude" ; @.9='Temperance'
|
||||
do #=1 while @.#\==''; end; #=#-1; w=length(#); return /*find # items.*/
|
||||
gen: @.=; @.1= '---the seven virtues---'; @.4= "Hope" ; @.7= 'Justice'
|
||||
@.2= '======================='; @.5= "Charity [Love]"; @.8= 'Prudence'
|
||||
@.3= 'Faith' ; @.6= "Fortitude" ; @.9= 'Temperance'
|
||||
do #=1 while @.#\==''; end; #= #-1; w= length(#); return /*get #items*/
|
||||
/*──────────────────────────────────────────────────────────────────────────────────────*/
|
||||
gnomeSort: procedure expose @.; parse arg n; k=2 /*N: is number items. */
|
||||
do j=3 while k<=n; p=k-1 /*P: is previous item.*/
|
||||
if @.p<<=@.k then do; k=j; iterate; end /*order is OK so far. */
|
||||
_=@.p; @.p=@.k; @.k=_ /*swap two @ entries. */
|
||||
k=k-1; if k==1 then k=j; else j=j-1 /*test for 1st index. */
|
||||
gnomeSort: procedure expose @.; parse arg n; k= 2 /*N: is number items. */
|
||||
do j=3 while k<=n; p= k - 1 /*P: is previous item.*/
|
||||
if @.p<<=@.k then do; k= j; iterate; end /*order is OK so far. */
|
||||
_= @.p; @.p= @.k; @.k= _ /*swap two @ entries. */
|
||||
k= k-1; if k==1 then k=j; else j= j-1 /*test for 1st index. */
|
||||
end /*j*/
|
||||
return
|
||||
/*──────────────────────────────────────────────────────────────────────────────────────*/
|
||||
show: do j=1 for #; say ' element' right(j,w) arg(1)":" @.j; end; return
|
||||
show: do j=1 for #; say ' element' right(j, w) arg(1)":" @.j; end; return
|
||||
|
|
|
|||
|
|
@ -0,0 +1,25 @@
|
|||
Private Function gnomeSort(s As Variant) As Variant
|
||||
Dim i As Integer: i = 1
|
||||
Dim j As Integer: j = 2
|
||||
Dim tmp As Integer
|
||||
Do While i < UBound(s)
|
||||
If s(i) <= s(i + 1) Then
|
||||
i = j
|
||||
j = j + 1
|
||||
Else
|
||||
tmp = s(i)
|
||||
s(i) = s(i + 1)
|
||||
s(i + 1) = tmp
|
||||
i = i - 1
|
||||
If i = 0 Then
|
||||
i = j
|
||||
j = j + 1
|
||||
End If
|
||||
End If
|
||||
Loop
|
||||
gnomeSort = s
|
||||
End Function
|
||||
|
||||
Public Sub main()
|
||||
Debug.Print Join(gnomeSort([{5, 3, 1, 7, 4, 1, 1, 20}]), ", ")
|
||||
End Sub
|
||||
Loading…
Add table
Add a link
Reference in a new issue