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©); T pop(); Queue(int rear1=0,int front1=0):rear(rear1),front(front1){} }; template<class T> void Queue<T>::Qpush(const T©) { 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; }
时间: 2024-10-10 14:51:20