Einzelnen Beitrag anzeigen

Chiqupon

Registriert seit: 7. Okt 2013
6 Beiträge
 
#7

AW: BubbleSort Problem

  Alt 8. Dez 2013, 03:55
Klappt auch nicht hier mal mein Quellcode:
Code:
unit Unit1;

{$mode objfpc}{$H+}

interface

uses
  Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls;

type

  { TForm1 }

  TForm1 = class(TForm)
    Button1: TButton;
    ListBox1: TListBox;
    ListBox2: TListBox;
    procedure Button1Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure BubbleSort;
  private
    { private declarations }
  public
    { public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.lfm}
procedure TForm1.BubbleSort;
var
  i, j : Integer;

  procedure Swap (const Index0, Index1 : Integer);
  var
    i0, i1 : Integer;
    s : string;
  begin
    i0 := StrToInt (ListBox1.Items [Index0]);
    i1 := StrToInt (ListBox1.Items [Index1]);
    if i0 > i1 then
      begin
        s := ListBox1.Items [Index0];

        ListBox1.Items [Index0] := ListBox1.Items [Index1];
        ListBox1.Items [Index1] := s
      end
  end;

begin
  for i := 0 to ListBox1.Items.Count - 1 do
    for j := ListBox1.Items.Count - 1 downto i do
      Swap (i, j)
end;
{ TForm1 }

procedure TForm1.Button1Click(Sender: TObject);
begin
  ListBox1.Items.Add (IntToStr (Random (100) - 1));
  ListBox2.Items.Assign (ListBox1.Items);
  Bubblesort
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  Randomize;
end;

end.
  Mit Zitat antworten Zitat