Professional Documents
Culture Documents
Red Sekvencionalna Rep
Red Sekvencionalna Rep
TipQ; int VelQ; TipQ NizQ[maxsize]; int Front; int Rear; void InicirajQ(); bool PrazanQ(); bool PunQ(); void PushQ(TipQ); TipQ PopQ(); void InicirajQ() { VelQ = 0; Front = 0; Rear = 0; cout<<"Red inicijaliziran!"<<endl; } bool PunQ() { if( VelQ == maxsize) return true; else return false; } bool PrazanQ() { if(VelQ == 0) return true; else return false; } void PushQ(TipQ element) { if(PunQ()) { cout<<"Greska, red je pun!!!"<<endl; } else { NizQ[Rear] = element; Rear++; if (Rear >= maxsize) Rear = 0; VelQ++; cout<<"Elemenat dodat u red! "<<endl; }
} TipQ PopQ() { TipQ temp = 0; if (PrazanQ()) { cout<<"Greska, red je prazan!"<<endl; } else { temp = NizQ[Front]; Front++; if (Front >= maxsize) Front = 0; VelQ--; cout<<"Elemenat uklonjen iz reda!"<<endl; } return temp; } #endif