Just another update

This commit is contained in:
Ingy döt Net 2015-02-20 00:35:01 -05:00
parent a25938f123
commit 00a190b0a6
6591 changed files with 94363 additions and 23227 deletions

View file

@ -0,0 +1,50 @@
class
COCKTAIL_SORT[G -> COMPARABLE]
feature
cocktail_sort(ar: ARRAY[G]): ARRAY[G]
require
ar_not_empty: ar.count>=1
local
swapped, finished: BOOLEAN
sol: ARRAY[G]
i,j : INTEGER
t: G
do
create sol.make_from_array (ar)
from
until finished= TRUE
loop
swapped := FALSE
from
i:= 1
until
i= ar.count-1
loop
if ar[i]> ar[i+1] then
t:= ar[i]
ar[i]:= ar[i+1]
ar[i+1]:= t
swapped:= true
end
i:= i+1
end
from j:= ar.count-1
until j= 1
loop
if ar[j]> ar[j+1] then
t:= ar[j]
ar[j]:= ar[j+1]
ar[j+1]:= t
swapped:= TRUE
end
j:= j-1
end
if swapped= FALSE then
finished:= TRUE
sol:= ar
end
end
Result:= sol
end
end

View file

@ -0,0 +1,18 @@
class
APPLICATION
inherit
ARGUMENTS
create
make
feature
make
do
test:= <<5,1,99,3,2>>
across test as t loop io.put_string (t.item.out + "%T") end
create cs
test:= cs.cocktail_sort(test)
across test as ar loop io.put_string (ar.item.out+"%T") end
end
cs: COCKTAIL_SORT[INTEGER]
test: ARRAY[INTEGER]
end