/ Published in: C++
Zadatak 3
Expand |
Embed | Plain Text
#include<iostream> using namespace std; struct podaci{ int a; int b,c,d; }; typedef int element; struct reda{ podaci brojevi[10000]; element front,rear; }; int AddOne(int n){ return((n+1)%10000); } bool IsEmptyQ(reda *Q){ if(AddOne(Q->rear)==Q->front) return 1; else return 0; } podaci FrontQ(reda *Q){ if(IsEmptyQ(Q)) cout<<"red je prazan"<<endl; return Q->brojevi[Q->front]; } void EnQueueQ(podaci x, reda *Q){ if(AddOne(AddOne(Q->rear))==Q->front) cout<<"Nije dodan novi element jer je red pun"<<endl; else{ Q->rear=AddOne(Q->rear); Q->brojevi[Q->rear]=x; } } void DeQueueQ(reda *Q){ if(IsEmptyQ(Q)) cout<<"red je prazan"<<endl; else Q->front=AddOne(Q->front); } reda *InitQ(reda *Q){ Q=new reda; Q->front=0; Q->rear=9999; return Q; }
You need to login to post a comment.
