Einzelnen Beitrag anzeigen

rossinie00

Registriert seit: 9. Mai 2004
Ort: Nonnweiler
62 Beiträge
 
#4

Re: Übung: Array und Bubble sort

  Alt 8. Nov 2004, 20:28
Delphi-Quellcode:
procedure TForm1.Button1Click(Sender: TObject);
var i,k,j,buffer,z,m,u: integer;
    zahlen,zahlendown,zufallsort,zufall: Array[1..10] of integer;
begin
  randomize;
    for i := 1 to 10 do
    begin
      zahlen[i] := i;
      sg.cells[1,i] := inttostr(zahlen[i]);
    end;
  for i := 1 to 10 do
    begin
      z := zahlen[i] + 1;
      sg.cells[2,i] := inttostr(z);
    end;
  for i := 1 to 10 do
    begin
      zahlendown[i] := i;
      m := zahlen[10] - zahlendown[i];
      sg.cells[3,i] := inttostr(m);
    end;
  for i := 1 to 10 do
    begin
      zufall[i] := random(100)+1;
      sg.cells[4,i] := inttostr(zufall[i]);
    end;

  { B U B B L E S O R T  Sortierverfahren beginnt hier}
 {
  for i:=10 downto 1 do
    begin
    for j:= 1 to i do
      begin
      if zufall[i]>zufall[j] then
        k := 0;
        inc(k);
        begin
          buffer:= zufall[i];
          zufall[i]:= zufall[j];
          zufall[j]:= buffer;
          sg.cells[5,k] := inttostr(zufall[j]);
        end;
      end;
    end;
              }

  for i:=1 to 10 -1 do
    begin
      for j:= 10 downto i do //Vom letzten bis zum i.-Element
        begin
          if zufall[j] < zufall[j-1] then //wenn j.-Element kleiner als j.-1-Element...
            begin //..tauschen:
              buffer := zufall[j-1]; //Wert des j.-1-Elements in Hilfsvariable
              zufall[j-1] := zufall[j];//j.-1-Element soll j.-Element werden
              zufall[j] := buffer; //j.-Element-Inhalt soll Hilfsvariable sein
            end;
     end;
Das kommt bei dem code:
Miniaturansicht angehängter Grafiken
unbenannt-1_102.jpg  
  Mit Zitat antworten Zitat