/ Published in: C++
deskripšn
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
#include <iostream> using namespace std; typedef int element; struct red{ int br; red *slijedeci; red *front,*rear; }; typedef struct red *ele; int FrontQ(red *jedan){ if(jedan->rear!=jedan->front) return jedan->front->slijedeci->br; else{ cout<<"Red je prazan!"; exit(0); } } void EnqueueQ(int x,red *jedan){ red *novi=new red; novi->br=x; novi->slijedeci=NULL; jedan->rear->slijedeci=novi; jedan->rear=novi; } void DequeueQ(red *jedan){ red *brisani=new red; if(jedan->rear!=jedan->front){ brisani=jedan->front; jedan->front=brisani->slijedeci; delete brisani; }else{ cout<<"Red je prazan!"; exit(0); } } void InitQ(red *jedan){ red*novi=new red; jedan->rear=novi; jedan->front=novi; novi->slijedeci=NULL; } int IsEmptyQ(red *jedan){ if(jedan->front==jedan->rear) return (-1); else return 0; }