-1
我試圖將我的C++代碼轉換爲Pascal,我確信我的代碼正在工作。轉換後,一切進展順利,除了結果與我的C++代碼不一樣 - 它不像C++中那樣排序。 這是我的Pascal:我的快速排序程序似乎沒有做任何事情
program try_quicksorting;
uses crt;
var
num: array[1..20] of integer;
x, y, a: integer;
again: char;
procedure quickSort(arr: array of integer; left, right:integer);
var
i:integer; {pointer for my left side}
j:integer; {pointer for my right side}
tmp:integer;
pivot:integer;
begin
i:=left;
j:=right;
pivot := arr[(left + right) div 2];
while (i <= j) do
begin
while (arr[i] < pivot) and (arr[j] < pivot) do
i:=i+1;
while (arr[j] > pivot) and (arr[i] > pivot) do
j:=j-1;
if(i <= j) then
begin
tmp:=arr[i];
arr[i]:=arr[j];
arr[j]:=tmp;
i:=i+1;
j:=j-1;
end;
end;
if j > left then
quickSort(arr, left, j);
if i < right then
quickSort(arr, i, right);
end;
begin
clrscr;
x:=1;
repeat
clrscr;
writeln('******************************************************');
write('Records: ');
a:=1;
while(a<x) do
begin
write(num[a], ' ');
a:=a+1;
end;
writeln('');
writeln('******************************************************');
write('Enter a number: ');
readln(num[x]);
writeln('------------------------------------------------------');
repeat
write('Again[Y/N]: ');
read(again);
if(again = 'y') or (again = 'Y') or (again = 'n') or (again = 'N')then
x:=x+1
else
writeln('Invalid input! Please press Y for Yes and N for No.');
until (again = 'y') or (again = 'Y') or (again = 'n') or (again = 'N');
until (again = 'n') or (again = 'N');
readln;
quickSort(num,1,x);
write('Sorted Form: ');
y:=1;
while (y<x) do
begin
write(num[y], ' ');
y:=y+1;
end;
readln;
end.
就是這樣。我希望你立即樣的反應:)
使用「不」或「不」而不是「不」;使用「我是」或「我是」而不是「im」;使用「立即」而不是「immidiate」。 – 2014-12-06 14:04:31
對不起,你是語法納粹嗎?無論如何,你有關於我的問題的答案嗎? o.O – user3187367 2014-12-06 14:23:33