顺序队列

#ifndef SEQUEUE_H
#define SEQUEUE_H

#include <iostream>
#include <assert.h>


template<typename T>
	class SeQueue
	{
		private:
			int size;
			
			int front;
			int back;
			T* contain;

		public:
			SeQueue():size(0),front(0),back(0),contain(NULL){}
			SeQueue(int MaxSize);

			bool IsFull();
			bool IsEmpty();

			void EnQueue(T& element);
			T DelQueue();
			T& GetFront();

			void MakeEmpty();
	};

template<typename T>
	SeQueue<T>::SeQueue(int MaxSize)
	{
		size = MaxSize + 1;
		front = 0;
		back = 0;
		contain = new T[MaxSize+1];
	}

template<typename T>
	bool SeQueue<T>::IsFull()
	{
		return (back+1)%size == front;
	}

template<typename T>
	bool SeQueue<T>::IsEmpty()
	{
		return front==back;
	}

template<typename T>
	void SeQueue<T>::EnQueue(T& element)
	{
		assert(!IsFull());
		contain[back] = element;
		back = (back+1)%size;
	}

template<typename T>
	T& SeQueue<T>::GetFront()
	{
		assert(!IsEmpty());
		return contain[front];
	}

template<typename T>
	T SeQueue<T>::DelQueue()
	{
		assert(!IsEmpty());
		int old = front;

		front = (front + 1)%size;
		return contain[old];
	}

#endif



你可能感兴趣的:(顺序队列)