Return to Snippet

Revision: 53821
at December 2, 2011 22:39 by vimandic


Initial Code
typedef int element;

struct qu {
	elementtype elements[10000];
	element front,rear;
};

typedef struct qu queue;


int AddOne(int n) {
	return((n+1)%10000);
}


elementtype FrontQ(queue *Q) {
	if (AddOne((*Q).rear)==(*Q).front) {
		printf("Red je prazan");
		exit(0);
	}
	else
		return((*Q).elements[(*Q).front]);
}


void EnqueueQ(elementtype x,queue *Q) {
	if (AddOne(AddOne((*Q).rear))==(*Q).front) {
		printf("Red je popunjen");
		exit(0);
	}
	else {
		(*Q).rear=AddOne((*Q).rear);
		(*Q).elements[(*Q).rear]=x;
	}
}


void DequeueQ(queue *Q) {
	if (AddOne((*Q).rear)==(*Q).front) {
		printf("Red je prazan");
		exit(0);
	}
	else
		(*Q).front=AddOne((*Q).front);
}


void InitQ(queue *Q) {
	(*Q).rear=9999;
	(*Q).front=0;
}


int IsEmptyQ(queue *Q) {
	if (AddOne((*Q).rear)==(*Q).front)
		return(-1);
	else
		return(0);
}

Initial URL

                                

Initial Description
Implementacija reda pomoću polja

Initial Title
Impl reda pomocu polja

Initial Tags

                                

Initial Language
C++