Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //---------------------------------------------------------------------------
- #include <vcl.h>
- #pragma hdrstop
- #include "Unit1.h"
- //---------------------------------------------------------------------------
- #pragma package(smart_init)
- #pragma resource "*.dfm"
- TForm1 *Form1;
- //---------------------------------------------------------------------------
- __fastcall TForm1::TForm1(TComponent* Owner)
- : TForm(Owner)
- {
- }
- //typedef struct {char Name[20]; char Vname[20]; int Alter;} DatenTp;
- typedef int DatenTp;
- struct KnotenTp{DatenTp Data; KnotenTp* Next;} ;
- class Liste
- {
- private:
- KnotenTp* Head;
- KnotenTp* UL; //Unterliste
- int count;
- void Init(DatenTp); //erschafft Liste
- void Pfeil(KnotenTp* Von, KnotenTp* Nach);//setzt Pfeil von -> nach
- KnotenTp* Bilden(DatenTp); //erschafft neue "Kiste"
- public:
- Liste(); //liste wird initialisiert
- ~Liste(); //liste wird aus speicher gelöscht
- bool NotEoL(); //schaut ob noch in der Liste
- bool end();
- int GetCount();
- DatenTp operator[](int); //siehe NotEoL
- KnotenTp* Weiter(); //setzt UL ein weiter
- void Anfuegen(DatenTp);//fügt neuen kasten an
- DatenTp HoleDaten(); //holt daten, die dort stehen
- void Begin(); //setzt UL auf Head
- void Entfernen();
- };
- //---------------------------------------------------------------------------
- KnotenTp* Liste::Weiter()
- {
- if(NotEoL())
- UL=UL->Next;
- return UL;
- }
- //---------------------------------------------------------------------------
- void Liste::Begin()
- {
- UL=Head;
- }
- //---------------------------------------------------------------------------
- DatenTp Liste::operator[](int s)
- {
- Begin();
- for(int g=0;g<s-1;g++)
- {
- Weiter();
- }
- return HoleDaten();
- }
- //---------------------------------------------------------------------------
- void Liste::Pfeil(KnotenTp* Von, KnotenTp* Nach)
- {
- Von->Next=Nach;
- }
- //---------------------------------------------------------------------------
- bool Liste::NotEoL()
- {
- return UL->Next->Next!=0;
- }
- //---------------------------------------------------------------------------
- KnotenTp* Liste::Bilden(DatenTp D)
- {
- KnotenTp* NeuKnoten;
- NeuKnoten=new KnotenTp;
- NeuKnoten->Data=D;
- NeuKnoten->Next=0;
- return NeuKnoten;
- }
- //---------------------------------------------------------------------------
- int Liste::GetCount()
- {
- return count;
- }
- //---------------------------------------------------------------------------
- void Liste::Init(DatenTp Data)
- {
- KnotenTp* Tail;
- Head=Bilden(Data);
- Tail=Bilden(Data);
- Pfeil(Head,Tail);
- UL=Head;
- }
- //---------------------------------------------------------------------------
- DatenTp Liste::HoleDaten()
- {
- return UL->Next->Data;
- }
- //---------------------------------------------------------------------------
- void Liste::Anfuegen(DatenTp D)
- {
- KnotenTp* NeuKnoten;
- NeuKnoten=Bilden(D);
- Pfeil(NeuKnoten,UL->Next);
- Pfeil(UL,NeuKnoten);
- count++;
- Weiter();
- }
- //---------------------------------------------------------------------------
- bool Liste::end()
- {
- return NotEoL();
- }
- //---------------------------------------------------------------------------
- void Liste::Entfernen()
- {
- KnotenTp* LoeschKnoten;
- if (NotEoL())
- {
- LoeschKnoten=UL->Next;
- Pfeil(UL,LoeschKnoten->Next);
- delete LoeschKnoten;
- }
- }
- //---------------------------------------------------------------------------
- Liste::Liste()
- {
- DatenTp k=0;//{"NIX","NIX",0};
- count=0;
- Init(k);
- }
- //---------------------------------------------------------------------------
- Liste::~Liste()
- {
- }
- //---------------------------------------------------------------------------
- Liste L;
- //---------------------------------------------------------------------------
- void __fastcall TForm1::Button1Click(TObject *Sender)
- {
- L.Begin();
- for ( int i = 0; i < 5 ; i++)
- L.Anfuegen(random(20));
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::Button2Click(TObject *Sender)
- {
- Memo1->Lines->Add("Hier kommt die Liste");
- L.Begin();
- while ( L.NotEoL())
- {
- Memo1->Lines->Add(L.HoleDaten());
- L.Weiter();
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::Button5Click(TObject *Sender)
- {
- L.Weiter();
- Label2->Caption = L.HoleDaten();
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::Button6Click(TObject *Sender)
- {
- L.Begin();
- Label2->Caption = L.HoleDaten();
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::Button7Click(TObject *Sender)
- {
- L.Anfuegen(Edit1->Text.ToInt());
- L.Entfernen();
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::Button3Click(TObject *Sender)
- {
- Edit2->Text=IntToStr(L.GetCount());
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::Button4Click(TObject *Sender)
- {
- int w=StrToInt(Edit3->Text);
- Memo1->Lines->Add("Wert an Stelle "+IntToStr(w)+": "+IntToStr(L[w]));
- }
- //---------------------------------------------------------------------------
Add Comment
Please, Sign In to add comment