2854 - 补全队列相关操作函数

在下列代码中,补全队列的相关操作函数:

#include<iostream>
using namespace std;

//队列的最大长度 
const int Maxsize = 100;

//定义队列 
struct Queue 
{
	int *queue;
	int head, tail;
};

//初始化队列
void InitQueue(Queue &q)
{

} 

//判断队列是否为满 
bool FullQueue(Queue &q)
{

} 

//判断队列是否为空
bool EmptyQueue(Queue &q)
{

} 

//入队 
void Push(Queue &q, int a)
{

}

//出队
int Pop(Queue &q)
{

}

//读取队头元素 
int PeekHead(Queue &q)
{

}

//读取队尾元素 
int PeekTail(Queue &q)
{

}

//清空队列
void ClearQueue(Queue &q)
{

}

int main()
{
	Queue q;
	InitQueue(q); //初始化队列 
	int a[8] = {5, 8, 2, 4, 15, 27, 42, 36};
	for(int i = 0; i < 8; i++)
		Push(q, a[i]); //入队 
	
	cout << PeekHead(q) << " ";   //读取队头元素
	cout << PeekTail(q) << endl; //读取队尾元素 

	cout << "head = " << q.head << endl;  //查看队头指针位置 
	cout << "tail = " << q.tail << endl;  //查看队尾指针位置 

	while(!EmptyQueue(q))  //判断队列是否为空  
		cout << Pop(q) << " ";  //出队 
	cout << endl;

	cout << "head = " << q.head << endl;  //查看队头指针位置 
	cout << "tail = " << q.tail << endl;  //查看队尾指针位置

	ClearQueue(q);  //清空队列 
}

输入

输出

补全程序后,运行程序,输出相应内容。

样例

输入


                

输出

5 36
head = 0
tail = 8
5 8 2 4 15 27 42 36
head = 8
tail = 8

来源

奇遇编程

题目参数

时间限制 1 秒
内存限制 32 MB
提交次数 0
通过人数 0
统计

上一题 下一题