Download as odt, pdf, or txt
Download as odt, pdf, or txt
You are on page 1of 2

#ifndef _RED_H #define _RED_H #include <iostream> using namespace std; const int maxsize = 20; typedef int

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

You might also like