/ 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) cout << "Prazan red."; else return ((Q->front)->next)->value; } void EnqueueQ(elementtype X, queue *Q){ element E = new 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) cout << "Prazan red."; else{ E = Q->front; Q->front = (Q->front)->next; delete E; }} bool IsEmptyQ(queue *Q){ if (Q->front==Q->rear) return true; else return false; } void InitQ(queue *Q){ element E = new qu; Q->front = E; Q->rear = E; E->next = NULL; }