Thema: Prism Min-Sort Verfahren

Einzelnen Beitrag anzeigen

GreenHorn3600

Registriert seit: 24. Jun 2007
165 Beiträge
 
#8

Re: Min-Sort Verfahren

  Alt 23. Nov 2007, 20:04
Mal 'n wenig QällKot spendier:
Delphi-Quellcode:
unit a_scheiss;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type
  TForm1 = class(TForm)
    Button1: TButton;
    Button2: TButton;
    Button3: TButton;
    Memo1: TMemo;
    Memo2: TMemo;
    procedure Button3Click(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure Button2Click(Sender: TObject);
  private
    { Private-Deklarationen }
    za: array [1 .. 20] of integer;
  public
    { Public-Deklarationen }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
var
  i,x,y: integer;
begin
  memo1.Clear; memo2.Clear;
  for I := 1 to 20 do za[i] := i;
  for I := 1 to 20 do
  begin
    x := random(20-i)+1;
    y := za[i];
    za[i] := za[x];
    za[x] := y;
  end;
  for i := 1 to 20 do
    memo1.Lines.Add(inttostr(za[i]));
end;

procedure TForm1.Button2Click(Sender: TObject);
var
  i,j,m,x: integer;
begin
  for I := 1 to 20 do
  begin
    x := i;
    for j := i+1 to 20 do
      if za[x] > za[j] then
        x := j;
      begin
        m := za[x];
        za[x] := za[i];
        za[i] := m;
      end;
    memo2.Lines.Add(inttostr(za[i]));
  end;
end;

procedure TForm1.Button3Click(Sender: TObject);
begin
  close;
end;

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

end.
Delphi-Quellcode:
object Form1: TForm1
  Left = 0
  Top = 0
  Caption = 'A Scheiß'
  ClientHeight = 216
  ClientWidth = 335
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'Tahoma'
  Font.Style = []
  OldCreateOrder = False
  OnCreate = FormCreate
  PixelsPerInch = 96
  TextHeight = 13
  object Button1: TButton
    Left = 4
    Top = 6
    Width = 75
    Height = 25
    Caption = 'erzeuge'
    TabOrder = 0
    OnClick = Button1Click
  end
  object Button2: TButton
    Left = 4
    Top = 32
    Width = 75
    Height = 25
    Caption = 'max sort'
    TabOrder = 1
    OnClick = Button2Click
  end
  object Button3: TButton
    Left = 4
    Top = 58
    Width = 75
    Height = 25
    Caption = 'close'
    TabOrder = 2
    OnClick = Button3Click
  end
  object Memo1: TMemo
    Left = 83
    Top = 0
    Width = 122
    Height = 213
    Lines.Strings = (
      'Memo1')
    TabOrder = 3
  end
  object Memo2: TMemo
    Left = 206
    Top = 0
    Width = 123
    Height = 213
    Lines.Strings = (
      'Memo2')
    TabOrder = 4
  end
end
//Edit: mal nachgelesen hab
  Mit Zitat antworten Zitat