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: 91: 92: 93: 94: 95: 96: 97: 98: 99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124:
| unit Unit1; interface uses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, Buttons, ExtCtrls; const leerBaum=nil; type TStrBaum= class(TObject) eintrag :string; anzahl :integer; links :TStrBaum; rechts :TStrBaum; constructor pflanzen(wort: string); procedure einfuegen(var wo: TStrBaum; wort: string); procedure ausgeben;
end;
TForm1 = class(TForm) Ausgabe: TListBox; Eingabe: TEdit; EingabeLabel: TLabel; EingabeBtn: TBitBtn; AusgabeBtn: TBitBtn; Memo1: TMemo; Button1: TButton; Button2: TButton; LabeledEdit1: TLabeledEdit; procedure FormCreate(Sender: TObject); procedure EingabeBtnClick(Sender: TObject); procedure AusgabeBtnClick(Sender: TObject); procedure EingabeKeyPress(Sender: TObject; var Key: Char); procedure Button1Click(Sender: TObject); procedure zerstueckeln(Sender: TObject); procedure MemoClick(Sender: TObject); private public end;
var Form1: TForm1; Baum: TStrBaum;
implementation {$R *.DFM}
constructor TStrBaum.pflanzen(wort: string); begin TObject.create; anzahl:=1; links:=leerBaum; rechts:=leerBaum; eintrag:=wort; end;
procedure TStrBaum.einfuegen(var wo: TStrBaum; wort: string); begin if wo=leerBaum then wo:=TStrBaum.pflanzen(wort) else with wo do if wort<eintrag then links.einfuegen(links, wort) else if wort>eintrag then rechts.einfuegen(rechts, wort) else inc(anzahl); end;
procedure TStrBaum.ausgeben; var zeile: string; begin if assigned(self) then begin links.AUSGEBEN; zeile:=IntToStr(anzahl); zeile:=copy(' '+zeile,6-length(zeile),6)+' '+eintrag; Form1.Ausgabe.items.add(zeile); rechts.AUSGEBEN; end; end;
procedure TForm1.FormCreate(Sender: TObject); begin baum:=nil; end;
procedure TForm1.EingabeBtnClick(Sender: TObject); begin if Eingabe.text<>'' then Baum.einfuegen(Baum, Eingabe.text); Eingabe.clear; ActiveControl:=Eingabe; end;
procedure TForm1.AusgabeBtnClick(Sender: TObject); begin Ausgabe.clear; Baum.ausgeben; ActiveControl:=Eingabe; end;
procedure TForm1.EingabeKeyPress(Sender: TObject; var Key: Char); begin if key in[#13,#32] then EingabeBtnClick(sender); end;
procedure TForm1.zerstueckeln(Sender: TObject); var i:integer; begin i:=1; while i+3<length(memo1.Text) do begin eingabe.text:=copy(Memo1.text,i,3); i:=i+1; EingabeBtnClick(sender); end; eingabe.Text:='Eingabe'; memo1.text:='--->FERTIG<---'+memo1.Text; memo1.Font.Color:=clred; end;
procedure TForm1.Button1Click(Sender: TObject); begin if memo1.text<>'' then zerstueckeln(sender); end;
procedure TForm1.MemoClick(Sender: TObject); begin memo1.font.color:=clblack; end;
end. |