Initial data commit

This commit is contained in:
Ingy döt Net 2023-07-01 11:58:00 -04:00
parent 72d218235f
commit f23f22d71c
199087 changed files with 3378941 additions and 0 deletions

View file

@ -0,0 +1,70 @@
class
COMB_SORT [G -> COMPARABLE]
feature
combsort (ar: ARRAY [G]): ARRAY [G]
-- Sorted array in ascending order.
require
array_not_void: ar /= Void
local
gap, i: INTEGER
swap: G
swapped: BOOLEAN
shrink: REAL_64
do
create Result.make_empty
Result.deep_copy (ar)
gap := Result.count
from
until
gap = 1 and swapped = False
loop
from
i := Result.lower
swapped := False
until
i + gap > Result.count
loop
if Result [i] > Result [i + gap] then
swap := Result [i]
Result [i] := Result [i + gap]
Result [i + gap] := swap
swapped := True
end
i := i + 1
end
shrink := gap / 1.3
gap := shrink.floor
if gap < 1 then
gap := 1
end
end
ensure
Result_is_set: Result /= Void
Result_is_sorted: is_sorted (Result)
end
feature {NONE}
is_sorted (ar: ARRAY [G]): BOOLEAN
--- Is 'ar' sorted in ascending order?
require
ar_not_empty: ar.is_empty = False
local
i: INTEGER
do
Result := True
from
i := ar.lower
until
i = ar.upper
loop
if ar [i] > ar [i + 1] then
Result := False
end
i := i + 1
end
end
end

View file

@ -0,0 +1,32 @@
class
APPLICATION
create
make
feature
make
do
test := <<1, 5, 99, 2, 95, 7, -7>>
io.put_string ("unsorted" + "%N")
across
test as ar
loop
io.put_string (ar.item.out + "%T")
end
io.put_string ("%N" + "sorted:" + "%N")
create combsort
test := combsort.combsort (test)
across
test as ar
loop
io.put_string (ar.item.out + "%T")
end
end
combsort: COMB_SORT [INTEGER]
test: ARRAY [INTEGER]
end