模板实现循环队列

const int MAXSIZE = 10;

#define MAX_BUF 10;
#include <assert.h>
template<class T>
class Queue
{ 
private:
T array1[MAXSIZE];
int rear;
int front;

public:
void Qpush(const T&copy);
T pop();
Queue(int rear1=0,int front1=0):rear(rear1),front(front1){}

};


template<class T>
void Queue<T>::Qpush(const T&copy)
{ int tmp=(rear+1)%MAXSIZE ;
assert(tmp!=front); 

array1[rear]=copy;
rear=(rear+1)%MAXSIZE ;

}
template<class T>
T Queue<T>::pop(){
T tmp=array1[front];
front=(front+1)%MAXSIZE ;
return tmp;
}

  

#include<iostream>
using namespace std;
#include"Queue.h"
int main(){
    Queue<int> s1;
    s1.Qpush(5);
    s1.Qpush(18);
    int temp=s1.pop();
    cout<<temp<<endl;


}
View Code

 

posted @ 2015-04-23 10:55  kkshaq  阅读(204)  评论(0编辑  收藏  举报