Reja Stek, navbat va deklarni massiv yordamida tasvirlash va ul
void Remove(int t) {
if (t= =0) exit(1);
t--;
return stack[t];
}
void Empty(int t) {
if (t= =0) p=1;
else p=2;
}
void Full(int t) {
if (t= =max_st) p=1;
else p=2;
}
Navbatdagi asosiy amallar Faraz qilaylik, navbat bir o‘lchamli massiv ko‘rinishida ifodalangan bo‘lib, uning uzunligi max_q ga teng bo‘lsin, ya’ni queue[max_q]. Bu erda first –navbat boshi, last- navbat oxiri, x esa BT turga tegishli element.
void Insert(int last, BT x) {
if (last= =max_q) exit(1);
queue[last]=x;
last++;
}
void Remove(int first, last) {
if (first= =last) exit(1);
first++;
}
void Empty(int first, last) {
if (first= =last) p=1;
else p=2;
}
void Full(int last) {
if (last= =max_q) p=1;
else p=2;
}
Dekdagi asosiy amallar int kirit_left(int s){ if(isFull()){cout<< "\n dek to'ldi";n=R; return EXIT_SUCCESS;} for(int i=R;i>0;i--) a[i]=a[i-1]; a[0]=s;R++; }
int olish_left(){ if(isEmpty()){cout<< "\ndek bo'sh";return EXIT_SUCCESS;} int t=a[0]; for(int i=0;i a[i]=a[i+1]; R--; return t; }
Stekka element kiritish algoritmi 1. yangi element yaratish
2. uning info maydoniga ma’lumot kiritish
3. agar ro’yhat bo’sh bo’lsa, ro’yhat boshi ko’rsatkichini ushbu elementga to’g’irlaymiz va yangi element ptr maydoniga NULL yozamiz, ya’ni if(Lst==NULL){Lst=p; p->ptr=NULL} Lst 4. Aks holda, ya’ni ro’yhat bo’sh bo’lmasa, yangi yaratilayotgan element ptr maydoniga ro’yhatning 1-elementi adresini yozamiz:
p->ptr = Lst;
5. ro’yhat boshi ko’rsatkichini yangi elementga tog’irlaymiz.
Lst=p;