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
Do'stlaringiz bilan baham: |