第31行提示的
#include
#include <stdlib.h>
#define Maxsize 10
using namespace std;
class Queue
{
private:
int data[Maxsize];
int front, rear;
public:
Queue* InitQueue(Queue* q)
{
q = (Queue*)malloc(sizeof(Queue));
q->front = q->rear = 0;
return q;
}
bool IsEmpty(Queue* q)
{
return q->front == q->rear;
}
bool DeleteQueue(Queue*& q)
{
delete q;
}
bool InQueue(Queue*& q, int e)
{
if ((q->rear + 1) % Maxsize == q->front)
return false;
q->data[rear] = e;
q->rear = (q->rear + 1) % Maxsize;
return true;
}
bool OutQueue(Queue*& q, int e)
{
if (q->front == q->rear)
return false;
q->front = (q->front + 1) % Maxsize;
e = q->data[front];
return true;
}
void Number(int n)
{
Queue* q = new Queue;
int e = 0;
InitQueue(q);
for (int i = 0; i <= n; i++)
InQueue(q, i);
while (!IsEmpty(q))
{
OutQueue(q, e);
cout << e;
if (!IsEmpty(q))
{
OutQueue(q, e);
InQueue(q, e);
}
}
cout << endl;
delete q;
}
};
int main()
{
Queue St;
int n;
cout << "请输入队伍人数:" << endl;
cin >> n;
St.Number(n);
system("pause");
}