부탁드립니다...
애써서 코딩을 했는데 실행을 해도
이상한 결과가 나오네요...
어디가 잘못되었죠/////????
제발 부탁드립니다....
--------------머지 소트....소스.----------------------------
program Project1;
{$APPTYPE CONSOLE}
uses SysUtils;
const
maxsize = 50;
type
afile = array[1..maxsize] of integer;
var
list,TEMP : afile;
step : integer;
n,size : integer;
procedure printlist(list : afile;
step,n : integer);
var
i : integer;
begin
write('** step',step:2,'**');
for i := 1 to n do
write(list[i]:4);
writeln;
writeln;
end;
procedure mpass(var x,y : afile;
num,size : integer);
var
i,j : integer;
procedure merge(var A,B : afile;
r,m,n : integer);
var
i,j,k,p : integer;
begin
i := r;
k := r;
j := m+1;
while((i <= m) and (j <= n)) do
begin
if A[i] <= A[j] then
begin
B[k] := A[i];
i := i+1
end
else
begin
B[k] := A[j];
j := j+1;
end;
k := k+1;
end;
if i > m then
for p := j to n do
B[k+p-i] := A[p]
else
for p := i to m do
B[k+p-1] := A[p];
end;
begin i := 1;
while i <= (num-2*size+1) do
begin
merge(X,Y,i,i+size-1,i+2*size-1);
i := i+2*size;
end;
if(i+size-1) < num then
merge(X,Y,i,i+size-1,num)
else
for j := i to num do
Y[j] := X[j];
end;
begin
n := 0;
while not eoln do
begin
n := n+1;
read(list[n]);
end;
step :=0;
printlist(list,0,n);
size := 1;
while size < n do
begin
step := step+1;
mpass(list,TEMP,n,size);
printlist(TEMP,step,n);
size := size*2;
step := step+1;
mpass(TEMP,list,n,size);
printlist(list,step,n);
size := 2*size;
end;
end.