Return to Snippet

Revision: 53903
at December 3, 2011 06:00 by mlcorak


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);
}

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

elementtype FrontQ(queue *element){
	if (IsEmptyQ(element)){
		cout << "Red je prazan!" << endl;
		exit(1);
	}
	return (*element).elements[(*element).front];
}

void EnQueueQ(elementtype x , queue *element){
	if (AddOne(AddOne((*element).rear)) == (*element).front){
		cout << "Red je popunjen!" << endl;
	}
	(*element).rear = AddOne((*element).rear);
	(*element).elements[(*element).rear] = x;
};

void DeQueueQ(queue *element){
	if (IsEmptyQ(element)){
		cout << "Red je prazan!" << endl;
		exit(1);
	}
	(*element).front = AddOne((*element).front);
}

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

Initial URL

                                

Initial Description
datoteka zaglavlja

Initial Title
datoteka cirkularno polje

Initial Tags

                                

Initial Language
C++