第2个回答 2007-06-01
#include <stdio.h>
void main()
{
int a[4];
int i, j, temp;
printf("input four integer:\n");
scanf("%d%d%d%d", &a[0], &a[1], &a[2], &a[3]);
for(i = 0; i < 3; i++) /*排序*/
for(j = i + 1; j < 4; j++)
{
if(a[i] > a[j])
{
temp = a[i];
a[i] = a[j];
a[j] = temp;
}
}
for(i = 0; i < 4; i++) /*输出*/
{
printf("%d\t", a[i]);
}
}
第3个回答 2007-06-02
pascal的快排
procedure qsort(l,r:longint);
var i,j,x,y:longint;
begin
i:=l;
j:=r;
x:=a[(l+r) div 2];
repeat
while a[i]<=x do inc(i);
while a[j]>=x do dec(j);
if i<j then begin
y:=a[i]; a[i]:=a[j]; a[j]:=y;
end;
until i>j;
if i>l then qsort(l,i);
if j<r then qsort(j,r);
end;
冒泡属于时间复杂度相当大的吧?不过只有四个数,还好。