线性表-顺序队列(循环队列)

//sqqueue.h

#ifndef SQQUEUE_H_H
#define SQQUEUE_H_H

#include 
#define MAXSIZE 10

using namespace std;

class SqQueue
{
	int data[MAXSIZE];
	int front;
	int rear;
public:
	SqQueue();
	~SqQueue();
	void ClearQueue();
	bool IsEmpty();
	void EnQueue(int item);
	void DeQueue();
	int GetLength();
	void PrintQueue();
};

#endif
//sqqueue.cpp

#include "sqqueue.h"

SqQueue::SqQueue()
{
	front = 0;
	rear = 0;
}

SqQueue::~SqQueue()
{

}

void  SqQueue::ClearQueue()
{
	front = 0;
	rear = 0;
}

bool  SqQueue::IsEmpty()
{
	return ( rear == front );
}

void  SqQueue::EnQueue(int item)
{
	if( (rear + 1) % MAXSIZE == front )
	{
		cerr<<"queue is full"<

using namespace std;

int main(int argc, char *argv[])
{
	SqQueue * queue = new SqQueue;
	queue->EnQueue(1);
	queue->EnQueue(2);
	queue->EnQueue(3);
	queue->EnQueue(4);
	queue->EnQueue(5);
	queue->PrintQueue();
	
	queue->DeQueue();
	queue->PrintQueue();
	queue->DeQueue();
	queue->PrintQueue();
	queue->DeQueue();
	queue->PrintQueue();
	if(queue->IsEmpty())
		cout<<"queue is empty."PrintQueue();
	if(queue->IsEmpty())
		cout<<"queue is empty."

你可能感兴趣的:(Datastructure)