冒泡排序
var arr:array[0..5] of integer; i,j:integer; itemp:integer; begin arr[0]:=1; arr[1]:=71; arr[2]:=5; arr[3]:=31; arr[4]:=2; arr[5]:=12; for i:=5 downto 1 do for j:=0 to i-1 do begin itemp:=arr[j]; if itemp<arr[j+1] then begin arr[j]:= arr[j+1]; arr[j+1]:=itemp; end; end; for i:= 0 to 5 do memo1.Lines.Add(inttostr(arr[i])); end;
结果:
71
31
12
5
2
1