队列的顺序存储结构(c++实现)

#pragma once
#include
using namespace std;
#define MAXSIZE 6
class Queue
{
public:
	Queue();
	~Queue();
	void Push_Queue();
	void Pop_Queue();
	bool IsEmpty();
	void Show_Queue();
	bool IsFull();
private:
	int *Base;
	int front;
	int rear;

};

#include"队列的顺序存储结构.h"
#include
using namespace std;
Queue::Queue()
{
	this->Base = new int[MAXSIZE];
	this->front = -1;
	this->rear = -1;
}
Queue::~Queue()
{

}
void Queue::Push_Queue()//入队
{
	if (this->IsFull())
	{
		cout << "入队失败,队列已满" << endl;
	}
	else
	{
		int x = 0;
		cout << "输入你想入队的数据" << endl;
		cin >> x;
		this->rear = (this->rear + 1) % MAXSIZE;
		this->Base[this->rear] = x;
		cout << "入队成功" << endl;
	}

}
void Queue::Pop_Queue()//出队
{
	if (this->IsEmpty())
	{
		cout << "队列空" << endl;
	}
	else
	{
		this->front = (this->front + 1) % MAXSIZE;
		cout << "出队元素为:" << this->Base[front] << endl;
	}
}
bool Queue::IsEmpty()
{
	return this->front == this->rear ? true : false;
}
void Queue::Show_Queue()
{
	int i = this->front;
	while (i != this->rear)
	{
		cout << this->Base[i+1]<< " ";
		i=(i+1)%MAXSIZE;
	}
}
bool Queue::IsFull()
{
	return (this->rear + 1) % MAXSIZE == this->front ? true : false;
}
#include"队列的顺序存储结构.h"
#include
using namespace std;
int main()
{
	Queue q;
	
	int i = 7;
	while (i!=0)
	{	
		cout << "0.退出  1.入队  2.出队  3.遍历" << endl;
		cin >> i;
		switch (i)
		{
		case 0:
			break;
		case 1:
			q.Push_Queue();
			break;
		case 2:
			q.Pop_Queue();
			break;
		case 3:
			q.Show_Queue();
			break;
		
		}
	}
}

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