Autor Beitrag
sirchillalot
Hält's aus hier
Beiträge: 1



BeitragVerfasst: Sa 23.11.02 12:55 
Wie kann ich 10 integerzahlen die in eimem 2 dim array stehen sortieren und sie in die 2 dimesion der größe nach sortiert hinein schreibe???
DeCodeGuru
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 1333
Erhaltene Danke: 1

Arch Linux
Eclipse
BeitragVerfasst: Sa 23.11.02 14:28 
ein netter kleiner Sotieralgo ist Bubble-Sort. Der ist zwar etwas langsam, aber dafür ist er auch einfach. Hier ist etwas Code (recht alt, deshalb verzeiht mir den etwas "doofen Code"):

ausblenden volle Höhe Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
unit Main;

interface

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

type
  TForm1 = class(TForm)
    Memo1: TMemo;
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    testsort: array [0..19] of Integer;
    procedure DoSort;
    procedure DoShow;
  public
    { Public-Deklarationen }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.DoSort;
var
  i, zw, ok: Integer;
begin
  repeat
    ok := 1;
    for i := 0 to 19 do
    begin
      if testsort[i] > testsort [i + 1] then
      begin
        zw := testsort [i];
        testsort[i] := testsort[i + 1];
        testsort[i + 1] := zw;
        ok := 0;                        
      end;
    end;
    DoShow;
  until ok = 1;
  DoShow;
end;

procedure TForm1.DoShow;
var
  i: Integer;
  tmp: String;
begin
  for i := 0 to 19 do
  begin
    if testsort[i] > 9 then
      tmp := tmp + '   '+IntToStr(testsort[i])
    else
      tmp := tmp + '     '+IntToStr(testsort[i]);
  end;
  Memo1.Lines.Add(tmp);
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  testsort[0] :=  19;
  testsort[1] :=  11;
  testsort[2] :=  18;
  testsort[3] :=  17;
  testsort[4] :=   5;
  testsort[5] :=   1;
  testsort[6] :=   9;
  testsort[7] :=  10;
  testsort[8] :=   6;
  testsort[9] :=   8;
  testsort[10] :=  2;
  testsort[11] := 16;
  testsort[12] := 15;
  testsort[13] := 12;
  testsort[14] :=  4;
  testsort[15] :=  7;
  testsort[16] :=  3;
  testsort[17] := 14;
  testsort[18] := 13;
  testsort[19] :=  0;
  DoShow;
  Application.ProcessMessages;
  DoSort;
end;


Kannst es ja mal probieren :wink:

_________________
Viele Grüße
Jakob
Christian S.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 20451
Erhaltene Danke: 2264

Win 10
C# (VS 2019)
BeitragVerfasst: Sa 23.11.02 20:37 
Hi!

Hier gibt es eine Zusammenstellung der beliebtesten Sortieralgorithmen.

Aber DeCodeGuru (der mit dem doofen Code :wink: ) hat schon recht: bei zehn Zahlen reicht Bubblesort völlig aus.

MfG,
Peter

_________________
Zwei Worte werden Dir im Leben viele Türen öffnen - "ziehen" und "drücken".
LCS
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 1305
Erhaltene Danke: 1

WIN 7, WIN 8
Delphi XE5, Delphi XE, Delphi 2007
BeitragVerfasst: So 24.11.02 14:26 
Und hier auch noch mal, fix und fertig mit Demoprogramm.

Gruss Lothar

_________________
Der BH ist für die Brust, der Plan ist für'n Ar...