/ Published in: C++
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
//red_pokazivac.h typedef int elementtype; struct tre{ elementtype value; re *next; }; struct tred{ re *front,*rear; }; typedef tred red; bool IsEmptyQ(red *Q){ if(Q->rear==Q->front) return 1; else return 0; } elementype FrontQ(red *Q){ if(IsEmptyQ(Q)==1){ return 0;} else return Q->front->next->value; } void EnQueueQ(elementtype x, red *Q){ red novi=new red; novi->next=NULL; novi->value=x; Q->rear->next=novi; Q->rear=novi; } void DeQueueQ(red *Q){ if(IsEmptyQ(Q)==1) return; else { red *brisi=Q->front; Q->front=Q->front->next; delete brisi; } void InitQ(red *Q){ Q=new red; tre *novi=new tre; Q->front=novi; Q->rear=novi; return; } //red_polje.h typedef int elementtype; struct tred{ elementtype elements[1000]; int front,rear; }; typedef tred red; int AddOne(int n) { return((n+1)%10000); } bool IsEmptyQ(red *Q){ if(AddOne(Q->front)==Q->rear) return 1; else return 0; } elementtype FrontQ(red *Q){ if(IsEmptyQ(Q)==1) return 0; else { return Q->elements[Q-front]; } } void EnQueueQ(elementtype x, red *Q){ if(IsEmptyQ(Q)==1) return; else { Q->rear=AddOne(Q->rear); Q->elements[Q->rear]=x; } } void DeQueueQ(red *Q){ if(IsEmptyQ(Q)==1) return; Q->front=AddOne(Q->front); } void InitQ(red *Q){ Q=new red; Q->front=0; Q->rear=9999; return; }