/ Published in: C++
implementacija reda pomocu pokazivaca
Expand |
Embed | Plain Text
struct tord{ int i; int j; tord *slijedeci; }; struct tred{ tord *p; tord *z; }; typedef tord element; typedef tred red; red *InitQ(red *&Q){ Q=new red; element *novi=new element; Q->p=novi; Q->z=novi; novi->slijedeci=NULL; return Q; }; element FrontQ(red *Q){ element elem; elem.i=elem.j=-1; if(Q->z!=Q->p){ elem.i=Q->p->slijedeci->i; elem.j=Q->p->slijedeci->j; } return elem; }; void EnQueueQ(element x, red *Q){ element *novi=new element; novi->i=x.i; novi->j=x.j; novi->slijedeci=NULL; Q->z->slijedeci=novi; Q->z=novi; }; void DeQueueQ(red *Q){ if(Q->z!=Q->p){ element *elem=Q->p; Q->p=Q->p->slijedeci; delete elem; } }; bool IsEmptyQ(red *Q){ if(Q->z!=Q->p) return false; else return true; };
You need to login to post a comment.
