Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Object-Pascal / Delphi-Language (https://www.delphipraxis.net/32-object-pascal-delphi-language/)
-   -   Delphi 2-Dimensionales Array sortieren? (https://www.delphipraxis.net/8447-2-dimensionales-array-sortieren.html)

axelf98 4. Sep 2003 18:17


2-Dimensionales Array sortieren?
 
Hallo!

Ich habe folgendes Problem:
Ich will eine Zuordnung aus Integerwerten sortieren...
(Array of Array[0..1] of integer)

0 1 2 3 4 5
3 2 4 1 2 1

und zwar nach den unteren Werten, beginnend mit dem Größten!
Dabei soll die oberen Werte mit sortiert werden.
Ich hab schon versucht Bubble- und Insertsort umzuschreiben, aber kommt nich das raus was ich gerne hätte, nämlich:

2 0 1 4 3 5
4 3 2 2 1 1

Vielleicht hat jemand sowas schon mal gemacht?! :idea:

axelf98 4. Sep 2003 19:48

Re: 2-Dimensionales Array sortieren?
 
Vielen Dank für eure Antworten *g*

Na dann helf ich mir halt selbst! :?

[Flox]Cauchy 5. Sep 2003 08:53

Re: 2-Dimensionales Array sortieren?
 
Vielleicht solltest Du den Benutzern hier mehr als 1,5 Stunden Zeit geben?!?

Delphi-Quellcode:
type
  TInt01 = array[0..1] of Integer;
  TFeld = array of TInt01;

procedure BubbleSort(var Feld: TFeld);
  var
    Fertig: Boolean;
    i: Integer;
    Hilfe: TInt01;
  begin
    repeat
      Fertig := True;
      for i := 0 to High(Feld) do
        if Feld[i, 1] > Feld[i+1, 1] then
          begin
            Hilfe := Feld[i];
            Feld[i] := Feld[i+1];
            Feld[i+1] := Hilfe;
            Fertig := False;
          end;
    until Fertig;
  end;
Ich hab's nicht getestet, aber probier's einfach mal!

axelf98 5. Sep 2003 09:32

Re: 2-Dimensionales Array sortieren?
 
Danke, ich hab das Problem jetzt schon selbst gelöst:

Delphi-Quellcode:
 function Loesungssystem.sort(Eingabe : TListe; n1 : integer) : TErgebnisListe;
  VAR x,y,i : integer;
    tausch : boolean;
     e : tergebnisliste;
 Begin
 y := n1;
 tausch := true;
 While tausch do
  Begin
   tausch := false;
   For x := 0 to y -1 do
    If Eingabe[x,1] > Eingabe[x+1,1] then
     Begin
      tausch := true;
      tausche (Eingabe[x,1], Eingabe[x+1,1]);  
      tausche (Eingabe[x,0], Eingabe[x+1,0]);  // Mitsortierung
     End;
   y := pred(y);
  End;
 End;


Alle Zeitangaben in WEZ +1. Es ist jetzt 17:55 Uhr.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz