Just another update
This commit is contained in:
parent
a25938f123
commit
00a190b0a6
6591 changed files with 94363 additions and 23227 deletions
|
|
@ -1,4 +1,8 @@
|
|||
{{sorting Algorithm}}{{wikipedia|Stooge sort}}Show the [[wp:Stooge sort|Stooge Sort]] for an array of integers. The Stooge Sort algorithm is as follows:
|
||||
{{sorting Algorithm}}{{wikipedia|Stooge sort}}
|
||||
{{omit from|GUISS}}
|
||||
Show the [[wp:Stooge sort|Stooge Sort]] for an array of integers.
|
||||
|
||||
The Stooge Sort algorithm is as follows:
|
||||
<b>algorithm</b> stoogesort(<b>array</b> L, i = 0, j = <b>length</b>(L)-1)
|
||||
<b>if</b> L[j] < L[i] <b>then</b>
|
||||
L[i] <b>↔</b> L[j]
|
||||
|
|
|
|||
|
|
@ -0,0 +1,28 @@
|
|||
class
|
||||
STOOGE_SORT
|
||||
feature
|
||||
stoogesort (ar: ARRAY[INTEGER]; i,j: INTEGER)
|
||||
require
|
||||
ar_not_empty: ar.count >= 0
|
||||
i_in_range: i>=1
|
||||
j_in_range: j <= ar.count
|
||||
boundary_set: i<=j
|
||||
local
|
||||
t: REAL_64
|
||||
third: INTEGER
|
||||
swap: INTEGER
|
||||
do
|
||||
if ar[j]< ar[i] then
|
||||
swap:= ar[i]
|
||||
ar[i]:=ar[j]
|
||||
ar[j]:= swap
|
||||
end
|
||||
if j-i >1 then
|
||||
t:= (j-i+1)/3
|
||||
third:= t.floor
|
||||
stoogesort(ar, i, j-third)
|
||||
stoogesort(ar, i+third, j)
|
||||
stoogesort(ar, i, j-third)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -0,0 +1,20 @@
|
|||
class
|
||||
APPLICATION
|
||||
inherit
|
||||
ARGUMENTS
|
||||
create
|
||||
make
|
||||
feature
|
||||
make
|
||||
do
|
||||
test:= <<2,5,66,-2, 0, 7>>
|
||||
io.put_string ("%Nunsorted:%N")
|
||||
across test as ar loop io.put_string (ar.item.out + "%T") end
|
||||
create stoogesort
|
||||
stoogesort.stoogesort (test, 1, test.count)
|
||||
io.put_string ("%Nsorted:%N")
|
||||
across test as ar loop io.put_string (ar.item.out + "%T") end
|
||||
end
|
||||
test: ARRAY[INTEGER]
|
||||
stoogesort: STOOGE_SORT
|
||||
end
|
||||
|
|
@ -0,0 +1,18 @@
|
|||
fn stoogeSort arr i: j: =
|
||||
(
|
||||
if i == unsupplied do i = 1
|
||||
if j == unsupplied do j = arr.count
|
||||
|
||||
if arr[j] < arr[i] do
|
||||
(
|
||||
swap arr[j] arr[i]
|
||||
)
|
||||
if j - i > 1 do
|
||||
(
|
||||
local t = (j - i+1)/3
|
||||
arr = stoogeSort arr i:i j:(j-t)
|
||||
arr = stoogeSort arr i:(i+t) j:j
|
||||
arr = stoogeSort arr i:i j:(j-t)
|
||||
)
|
||||
return arr
|
||||
)
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
a = for i in 1 to 15 collect random 1 20
|
||||
#(10, 2, 1, 19, 18, 20, 18, 5, 13, 2, 13, 9, 7, 10, 6)
|
||||
stoogeSort a
|
||||
#(1, 2, 2, 5, 6, 7, 9, 10, 10, 13, 13, 18, 18, 19, 20)
|
||||
Loading…
Add table
Add a link
Reference in a new issue