struct Queue { //Navbat nomli struktura e’loni
QNode *front, *rear; //oldinga va orqaga ko’rsatgichlar ko’rsatilmoqda.
Queue()
{
front = rear = NULL;
}
void enQueue(int x)
{
// Yangi LL tugunini yaratinsh
QNode* temp = new QNode(x);
/*Agar navbat bo'sh bo'lsa, unda yangi tugun ikkala old va orqa tomonda bo'ladi*/
if (rear == NULL) {
front = rear = temp;
return;
}
// Navbat oxirida yangi tugunni qo'shish va orqa tomonni o'zgartirish
rear->next = temp;
rear = temp;
}
// Kalitni berilgan navbatdan olib tashlash funktsiyasi
void deQueue()
{
// If queue is empty, return NULL.
if (front == NULL)
return;
// Oldingi old qismini saqlash va boshning bitta tugunini oldinga siljitish
QNode* temp = front;
front = front->next;
// Agar old NULL bo'lsa, u holda orqani NULL deb o'zgartirish
if (front == NULL)
rear = NULL;
delete (temp);
}
Do'stlaringiz bilan baham: |