顺序队列类实现(C++)

/* * SeqQueue.h * * Created on: Jul 15, 2010 * Author: kevin */ #include <stdlib.h> #include <iostream> using namespace std; #ifndef SEQQUEUE_H_ #define SEQQUEUE_H_ template<class T> class SeqQueue{ const static int MaxSize = 1000 ; private: T data[MaxSize]; int front; int rear; public: SeqQueue(){ front=0; rear=0; }; ~SeqQueue(){}; void in(T x){ if(isFull()){ cout<<"Queue is full!"<<endl; exit(0); } data[rear]=x; rear=(rear+1)%MaxSize; }; T out(){ if(isEmpty()){ cout<<"Queue is empty!"<<endl; exit(0); } T temp=data[front]; front=(front+1)%MaxSize; return temp; }; bool isEmpty(){ return front==rear; }; bool isFull(){ return (rear+1)%MaxSize==front; }; }; #endif /* SEQQUEUE_H_ */

你可能感兴趣的:(C++,2010)