Reja: Stek, navbat va deklarni massiv yordamida tasvirlash va ular ustida amal bajarish algoritmlari


Download 0.52 Mb.
bet2/3
Sana10.10.2023
Hajmi0.52 Mb.
#1697319
1   2   3
Bog'liq
8-9-10 Amaliyot ishlari uchun

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;


Download 0.52 Mb.

Do'stlaringiz bilan baham:
1   2   3




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling