/ Published in: C++
Implementacija reda pomoću pokazivaÄa
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
struct qu { elementtype value; struct qu *next; }; struct que { struct qu *front,*rear; }; typedef struct que queue; typedef struct qu *element; elementtype FrontQ(queue *Q) { if ((*Q).front==(*Q).rear) { printf("Red je prazan"); exit(0); } else return((*(*(*Q).front).next).value); } void EnqueueQ( elementtype x,queue *Q) { element e; e=(struct qu *)malloc(sizeof(struct qu)); (*e).value=x; (*e).next=NULL; (*(*Q).rear).next=e; (*Q).rear=e; } void DequeueQ(queue *Q) { element e; if ((*Q).front==(*Q).rear) { printf("Red je prazan"); exit(0); } else { e=(*Q).front; (*Q).front=(*(*Q).front).next; free(e); } } void InitQ(queue *Q) { element e; e=(struct qu *)malloc(sizeof(struct qu)); (*Q).front=e; (*Q).rear=e; (*e).next=NULL; } int IsEmptyQ(queue *Q){ if ((*Q).front==(*Q).rear) return(-1); else return(0); }