掲示板システム
ホーム
アクセス解析
カテゴリ
ログアウト
TObjectでご指導ねがいます。 (ID:37320)
名前
ホームページ(ブログ、Twitterなど)のURL (省略可)
本文
こうかな unit Unit3; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls; type TBlood = (blA,blB,blAB,blO); PItem = ^TItem; TItem = record Age : Integer; Blood: TBlood; end; TForm3 = class(TForm) Button1: TButton; ListBox1: TListBox; ListBox2: TListBox; procedure Button1Click(Sender: TObject); private { Private 宣言 } public procedure QuickSort(L, R: Integer); end; var Form3: TForm3; A: TList; implementation {$R *.dfm} function NewData(Age: Integer; Blood: TBlood): PItem; begin New (Result); Result.Age := Age; Result.Blood := Blood; end; procedure TForm3.QuickSort(L, R: Integer); var I, J,K,H: Integer; P, T: Pointer; S1,S2: String; Item1,Item2: PItem; begin repeat I := L; J := R; H := PItem(ListBox1.Items.Objects[(L+R) shr 1])^.Age; repeat K := 0; while K = 0 do begin if I < ListBox1.Items.Count then begin if PItem(ListBox1.Items.Objects[I]).Age < H then begin Inc(I); end else begin K := 1; end; end else begin K := 1; end; end; K := 0; while K = 0 do begin if I < ListBox1.Items.Count then begin if PItem(ListBox1.Items.Objects[J]).Age > H then begin Dec(J); end else begin K := 1; end; end else begin K := 1; end; end; //データ入れ替え if I <= J then begin S1 := ListBox1.Items[I]; S2 := ListBox1.Items[J]; Item1 := PItem(ListBox1.Items.Objects[I]); Item2 := PItem(ListBox1.Items.Objects[J]); ListBox1.Items[I] := S2; ListBox1.Items[J] := S1; ListBox1.Items.Objects[I] := TObject(Item2); ListBox1.Items.Objects[J] := TObject(Item1); Inc(I); Dec(J); end; until I > J; if L < J then QuickSort(L, J); L := I; until I >= R; end; procedure TForm3.Button1Click(Sender: TObject); var I: Integer; begin //データ作成 年齢データは random(99999) for I:=0 to 1023 do begin ListBox1.Items.AddObject(IntToStr(I),TObject( NewData(Random(99999),blA) )); end; //ソート QuickSort(0,ListBox1.Items.Count-1); //年齢データを ListBox2 に表示 for I:=0 to 1023 do begin ListBox2.Items.Add(IntToStr(PItem(ListBox1.Items.Objects[I]).Age)); end; //消す for I:=0 to 1023 do begin Dispose(PItem(ListBox1.Items.Objects[I])); end; end; end.
←解決時は質問者本人がここをチェックしてください。
更新する
戻る
掲示板システム
Copyright 2021 Takeshi Okamoto All Rights Reserved.