/ Published in: C++
Zadatak 3 - Strukture Podataka
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
#include <iostream> using namespace std; struct struktura{ int x, y; struktura *slijedeci; }; struct strukturaP{ struktura *front,*rear; }; typedef strukturaP queue; typedef struktura atrib; queue *InitQ(queue *&Q){ Q=new queue; atrib *novi=new atrib; Q->front=novi; Q->rear=novi; novi->slijedeci=NULL; return Q; }; atrib FrontQ(queue *Q){ atrib pom; pom.x=pom.y=-1; if(Q->rear != Q->front){ pom.x=Q->front->slijedeci->x; pom.y=Q->front->slijedeci->y; } return pom; }; void EnQueueQ(atrib x, queue *Q){ atrib *novi=new atrib; novi->x=x.x; novi->y=x.y; novi->slijedeci=NULL; Q->rear->slijedeci=novi; Q->rear=novi; }; void DeQueueQ(queue *Q){ if(Q->rear != Q->front){ atrib *pom=Q->front; Q->front=Q->front->slijedeci; delete pom; } else cout<<"Prazan red!"<<endl; }; bool IsEmptyQ(queue *Q){ if(Q->rear != Q->front) return false; return true; };