1樓:匿名使用者
var a:array[1..100]of integer;
i,n:integer;
procedure pop(l,r:integer);
var p1,p2,x,t:integer;
begin
p1:=l; p2:=r; x:=a[(l+r)div 2];
repeat while a[p1]<=x do inc(p1);
while a[p2]>=x do dec(p2);
if p1<=p2 then begin
t:=a[p1]; a[p1]:=a[p2]; a[p2]:=t;
inc(p1); dec(p2);
end;
until p1>p2;
if l
if p1
end;
begin
readln(n);
for i:=1 to n do read(a[i]);
pop(1,n);
for i:=1 to n do write(a[i],' ');
end.
2樓:匿名使用者
//注:random隨機生成起始點,防止qksort效率退化.(當原資料已接近排好順序時會卡qsort的)
program qksort;
vari,n:integer;
a:array[1..10000]of integer;
procedure qsort(h,t:integer);
varx,y,i,temp1,temp2:integer;
begin
x:=h;y:=t;
temp1:=random(t-h)+h;
if temp1<>x then
begin
temp2:=a[temp1];
a[temp1]:=a[x];
a[x]:=temp2;
end;
i:=a[x];
while x=i) do dec(y);
if x
begin
a[x]:=a[y];
inc(x);
end;
while (x
if x
begin
a[y]:=a[x];
dec(y);
end;
end;
a[x]:=i;
if h
if x+1
end;
begin
readln(n);
for i:=1 to n do
readln(a[i]);
randomize;
qsort(1,n);
for i:=1 to n do
writeln(a[i]);
end.
求pascal程式埃及分數
問題補充 用pascal語言寫出源 解答 這是一道比較費腦筋的題目.花了我半個小時才理出了個頭緒.要利用90個埃及分數 1 2,1 3,1 4 2l的不行吧,埃及分數要用a 優化的搜尋,表示很有壓力 var a,x,y integer begin write a readln a for x a 1...
求8數碼問題的A 演算法程式(PASCAL語言)
求8數碼a或a 演算法 用c語言 dfs hash 記憶化 爐灰出品。include define n 4 define swap a,b a a b b a b a a b int map n n hashta 99991 path 2000 min 150,book n n h 0,step 0...
急求 在家編制新的PASCAL程式為什麼會出現錯誤
翻譯下 錯誤15 檔案未找到 system.tpu system.tpu是pascal的核心單元,我們用的abs,trunc及所有常用語句都是這個單元中的,缺了這個單元肯定是沒法編譯的.檢查一下你的tp目錄下的unit目錄,看看有沒有system.tpu,沒有的話趕緊重灌.你是不是用vista了,軟...