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,63 @@
class
GNOME_SORT [G -> COMPARABLE]
feature
sort (ar: ARRAY [G]): ARRAY [G]
-- Sorted array in ascending order.
require
array_not_void: ar /= Void
local
i, j: INTEGER
ith: G
do
create Result.make_empty
Result.deep_copy (ar)
from
i := 2
j := 3
until
i > Result.count
loop
if Result [i - 1] <= Result [i] then
i := j
j := j + 1
else
ith := Result [i - 1]
Result [i - 1] := Result [i]
Result [i] := ith
i := i - 1
if i = 1 then
i := j
j := j + 1
end
end
end
ensure
Same_length: ar.count = Result.count
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,33 @@
class
APPLICATION
create
make
feature
make
do
test := <<7, 99, -7, 1, 0, 25, -10>>
io.put_string ("unsorted:%N")
across
test as ar
loop
io.put_string (ar.item.out + "%T")
end
io.new_line
io.put_string ("sorted:%N")
create gnome
test := gnome.sort (test)
across
test as ar
loop
io.put_string (ar.item.out + "%T")
end
end
test: ARRAY [INTEGER]
gnome: GNOME_SORT [INTEGER]
end