小甲鱼delphi学习作业19《冒泡排序》
作业源码:https://yanglu-115.lanzouq.com/ifW6q1ce0hbg
一、程序框图:
二、代码
1、提取编辑框数据到数组
1 procedure TForm1.Button1Click(Sender: TObject); 2 var 3 i:Integer; 4 begin 5 temp:=''; 6 Str:=Trim(edit1.Text); 7 k:=1; 8 for i:=1 to Length(Str) do 9 begin 10 if Str[i]<>#32 then 11 begin 12 temp:=temp+str[i]; 13 if (Str[i+1]=#32 ) or (i=Length(str)) then 14 begin 15 arr[k]:=StrToInt(temp); 16 ShowMessage(IntToStr(arr[k])); 17 temp:=''; 18 k:=k+1; 19 end 20 end 21 else 22 continue 23 end ; 24 end;
2、这些数排序并显示出来
1 procedure TForm1.btn1Click(Sender: TObject); 2 var 3 i,j,linshi:Integer; 4 5 begin 6 ShowMessage(IntToStr(k)); 7 linshi:=1 ; 8 for i:=1 to (k-2) do 9 begin 10 for j:=1 to k-1-i do 11 if arr[i]>arr[i+j] then 12 begin 13 linshi:=arr[i]; 14 arr[i]:=arr[i+j]; 15 arr[i+j]:=linshi; 16 end; 17 18 end; 19 for i:=1 to k-1 do 20 Label1.caption:=Label1.caption+' '+IntToStr(arr[i]); 21 end;