首页 > 其他 > 详细

模板实现循环队列

时间:2015-04-23 12:27:10      阅读:135      评论:0      收藏:0      [点我收藏+]
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

 

模板实现循环队列

原文:http://www.cnblogs.com/kkshaq/p/4449748.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!