posts - 6,  comments - 5,  trackbacks - 0
program p_1;
const
 n=10;
var
 s:array[1..n] of integer;
 m:integer;
procedure sort(lx,rx:integer);
var
 i,j,t:integer;
begin
 i:=lx; j:=rx; t:=s[i];
 repeat
   while (s[j]>t) and (i<j) do  j:=j-1;
   if (i<j) then
   begin
    s[i]:=s[j];
    i:=i+1;
    while (s[i]<t) and (i<j) do i:=i+1;
    if (i<j) then
    begin
     s[j]:=s[i];
     j:=j-1;
    end;
   end;
   until i=j;
   s[i]:=t; i:=i+1; j:=j-1;
   if (lx<j) then sort(lx,j);
   if (i<rx) then sort(i,rx);
end;
begin
 write('input data');
 for m:=1 to n do
  read(s[m]);
  sort(1,n);
 for m:=1 to n do
  write(s[m],' ');
end.
posted on 2005-08-18 22:23 李青 阅读(996) 评论(4)  编辑 收藏 引用

FeedBack:
# re: 快排 qksort
2006-07-05 15:02 | 高韫之
救急了
谢谢  回复  更多评论
  
# re: 快排 qksort
2007-05-27 15:54 | lala
有没有二分的快排程序?  回复  更多评论
  
# re: 快排 qksort
2007-05-27 15:56 | lala
大牛帮个忙  回复  更多评论
  
# re: 快排 qksort
2007-06-02 07:10 | kkxxlq
@lala 有点老方法
program binsearch;

const max=10;
var num:array[1..max] of integer;
i,n:integer;

procedure search(x,a,b:integer);
var mid:integer;
begin
if a=b then
if x=num[a] then writeln('Found:',a) else writeln('Number not found')
else begin
mid:=(a+b) div 2;
if x>num[mid] then search(x,mid,b);
if x<num[mid] then search(x,a,mid);
if x=num[mid] then writeln('Found:',mid);
end;
end;

begin
write('Please input 10 numbers in order:');
for i:=1 to max do read(num);
write('Please input the number to search:');
readln(n);
search(n,1,max);
end.  回复  更多评论
  
只有注册用户登录后才能发表评论。
<2006年7月>
2526272829301
2345678
9101112131415
16171819202122
23242526272829
303112345

常用链接

留言簿(1)

随笔档案

搜索

  •  

最新评论

阅读排行榜

评论排行榜