/ Published in: C++
Implementacija reda pomoću polja
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
typedef int element; struct qu { elementtype elements[10000]; element front,rear; }; typedef struct qu queue; int AddOne(int n) { return((n+1)%10000); } elementtype FrontQ(queue *Q) { if (AddOne((*Q).rear)==(*Q).front) { printf("Red je prazan"); exit(0); } else return((*Q).elements[(*Q).front]); } void EnqueueQ(elementtype x,queue *Q) { if (AddOne(AddOne((*Q).rear))==(*Q).front) { printf("Red je popunjen"); exit(0); } else { (*Q).rear=AddOne((*Q).rear); (*Q).elements[(*Q).rear]=x; } } void DequeueQ(queue *Q) { if (AddOne((*Q).rear)==(*Q).front) { printf("Red je prazan"); exit(0); } else (*Q).front=AddOne((*Q).front); } void InitQ(queue *Q) { (*Q).rear=9999; (*Q).front=0; } int IsEmptyQ(queue *Q) { if (AddOne((*Q).rear)==(*Q).front) return(-1); else return(0); }