List * n q new List; // Yangi
element hosil qilish
n->prev q w; // 1 - amal
n->next q w->next; // 2 - amal
if (w->next) {w->next->prev q n;} // 3 - amal
w->next q n; // 4 - amal
n->Data q data; // funksional
elementni initsializatsiya qilish
Qo‘yish har doim so‘nggi elementdan bajarilganligi uchun w- >next ning qiymati har doim nol bo‘ladi, ya’ni 3-amal hech qachon bajarilmaydi, shuning uchun uni tushirib qoldirish mumkin. Dasturning asosiy kodida bu amal tushirib qoldirilgan.
Dastur kodi
#include
#pragma hdrstop
#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
struct List
{
List* prev;
List* next;
AnsiString Data;
};
List* add(List* w, AnsiString data) // Ro‘yxatga element qo‘shish
{
List * n = new List;
n->prev = w;
n->next = w->next;
w->next = n;
n->Data = data;
return n;
}
List* del(List* w) // Ro‘yxatdan elementni o‘chirish
{
if(w->prev){w->prev->next = w->next;}
if(w->next){w->next->prev = w->prev;}
List * r;
if(w->next) {r = w->next;} else {r = w->prev;}
delete w;
return r;
}
List First; // Ro‘yxatning boshi
List* Last = &First; // Ro‘yxatning oxiri
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
Memo1->Lines->Clear();
List* m = &First;
while(m)
{
Memo1->Lines->Add(m->Data);
m = m->next;
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button2Click(TObject *Sender)
{
Last = add(Last,Edit1->Text);
Edit1->Text = "";
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button3Click(TObject *Sender)
{
Last = del(Last);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button4Click(TObject *Sender)
{
while(Last != &First)
{
Last = del(Last);
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormCreate(TObject *Sender)
{
First.next = 0;
First.prev = 0;
First.Data = "Ro‘yxatning boshi";
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormDestroy(TObject *Sender)
{
Button4->Click();
Foydalangan adabiyotlar hamda elektron saytlar:
1.P.Karimov,S.Irisqulov,A.Isaboyev “Dasturlash”Toshkenet Ozbekiston nashriyoti_2003 yil.
2.Sh.A.Nazirov, R.V.Qobulov “Obektga mo`ljallangan dasturlash” Toshkent-2009 yil.
3.H.Rahimov,T.Dehqonov C++ Zamonaviy dasturlash tillari.
4.Гради Бuч. Объектно –ориентированной анализ и проектирование с примерами приложений на С++. Невский диалект, 2001 г
5. Грехем И. Объектно ориентированные методы. Принсипы и практика. Вильямс. 2004
Internet elektron saytlar: www.ziyonet uz , www.nkmk.uz www.ndpu.uz, www.tdtu.library.uz
Do'stlaringiz bilan baham: |