Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
|
|
@ -0,0 +1,49 @@
|
|||
procedure CocktailShakerSort(A, Length);
|
||||
integer A, Length;
|
||||
integer BeginIdx, EndIdx; \mark the first and last index to check
|
||||
integer NewBeginIdx, NewEndIdx, II, T;
|
||||
begin
|
||||
BeginIdx:= 0;
|
||||
EndIdx:= Length - 1;
|
||||
|
||||
while BeginIdx <= EndIdx do
|
||||
begin
|
||||
NewBeginIdx:= EndIdx;
|
||||
NewEndIdx:= BeginIdx;
|
||||
for II:= BeginIdx to EndIdx - 1 do
|
||||
begin
|
||||
if A(II) > A(II + 1) then
|
||||
begin
|
||||
T:= A(II+1); A(II+1):= A(II); A(II):= T;
|
||||
NewEndIdx:= II;
|
||||
end;
|
||||
end;
|
||||
|
||||
\Decreases EndIdx because the elements after NewEndIdx are in correct order
|
||||
EndIdx:= NewEndIdx;
|
||||
|
||||
for II:= EndIdx downto BeginIdx - 1 do
|
||||
begin
|
||||
if A(II) > A(II + 1) then
|
||||
begin
|
||||
T:= A(II+1); A(II+1):= A(II); A(II):= T;
|
||||
NewBeginIdx:= II;
|
||||
end;
|
||||
end;
|
||||
|
||||
\Increases BeginIdx because elements before NewBeginIdx are in correct order
|
||||
BeginIdx:= NewBeginIdx + 1;
|
||||
end;
|
||||
end;
|
||||
|
||||
int Test, Len, I;
|
||||
begin
|
||||
Test:= [7, 6, 5, 9, 8, 4, 3, 1, 2, 0];
|
||||
Len:= 10;
|
||||
CocktailShakerSort(Test, Len);
|
||||
for I:= 0 to Len-1 do
|
||||
begin
|
||||
IntOut(0, Test(I));
|
||||
ChOut(0, ^ );
|
||||
end;
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue