数据结构与算法编程题18

循环队列相关代码。

#include 
using namespace std;

#define Maxsize 100
#define ERROR 0
#define OK 1
typedef int Elemtype;
typedef struct Queue
{
	Elemtype data[Maxsize];
	int front;
	int rear;
}Queue;

void Init_Queue(Queue &Q)
{
	Q.front = Q.rear = -1;
}

bool Empty_Queue(Queue& Q)
{
	if (Q.front == Q.rear)
	{
		cout << "队列为空" << endl;;
		return OK;
	}
	return ERROR;
}

bool Enter_Queue(Queue& Q, int x)
{
	if ((Q.rear + 1) % Maxsize == Q.front)
	{
		cout << "队列已满,无法继续入队!!!" << endl;
		return ERROR;
	}
	Q.data[Q.rear] = x;
	Q.rear = (Q.rear + 1) % Maxsize;
	return OK;
}

bool Leave_Queue(Queue& Q, int& x)
{
	if (Q.rear == Q.front)
	{
		cout << "队列为空,无法出队!!!" << endl;
		return ERROR;
	}
	x = Q.data[Q.front];
	Q.front = (Q.front + 1) % Maxsize;
	return OK;

}
int main(void)
{
	return 0;
}

你可能感兴趣的:(算法与数据结构,数据结构)