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

相关文章:

  • 2022-12-23
  • 2021-06-22
  • 2021-08-07
  • 2022-02-11
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-12-22
  • 2021-08-04
  • 2022-12-23
  • 2022-01-03
  • 2021-11-26
  • 2021-08-07
  • 2022-12-23
相关资源
相似解决方案