/ Published in: C++
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
typedef int element; struct qu { elementtype elements[10000]; int front,rear; }; typedef struct qu queue; int AddOne(int n) { return((n+1)%10000); } int FrontQ(queue *Q){ if (AddOne(*Q.rear)==(*Q.front)){ cout<<"Red je prazan!"<<endl; } else return (*Q.elements[*Q.front]) } void EnQueueQ(int x, queue*Q){ if(AddOne(AddOne(*Q.rear)))==(*Q.front){ cout<<"Red je pun!"<<endl; } else { *Q.rear=AddOne(*Q.rear); *Q.elements[*Q.rear]=x; } } void DeQueueQ(queue *Q){ if(AddOne(*Q.rear)==*Q.front)){ cout<<"Red je prazan!"<<endl; } else *Q.front=AddOne(*Q.front); } void InitQ(queue *Q){ *Q.front=0; *Q.rear=10000-1; } int IsEmpty (queue Q){ if (AddOne(Q.rear)==Q.front) return 1; else return 0; }