AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Thema durchsuchen
Ansicht
Themen-Optionen

BubbleSort Problem

Ein Thema von Chiqupon · begonnen am 7. Dez 2013 · letzter Beitrag vom 9. Dez 2013
 
Chiqupon

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

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
 


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 04:34 Uhr.
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz