1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
|
#include<iostream> #include<cmath> #include<cstring> #include<cstdlib> #include"ArraY.h" using namespace std;
//数组队列 template<typename T> class ArrayQueue{ private: int size; Array<T> *data;
public: ArrayQueue(int capacity){ data=new Array<T>(capacity+1); this->size=0; } ArrayQueue(){ data=new Array<T>(); this->size=0; }
//获取队列的容量 int getCapacity(){ return data->getArray(); }
//获取队列中元素的个数 int getSize(){ return size; }
//判断队列是否为空 bool isEmpty(){ return data->isEmpty(); }
//入队操作 void enqueue(T elem){ data->addLast(elem); size++; }
//出队操作,并且返回出队的元素 T dequeue(){ size--; return data->remove(size); }
//查看队首的元素 T getFront(){ return data->get(size-1); }
//打印整个队列 void PrintArrayQueue(){ for(int i=0;i<size;i++){ cout<<data->get(i)<<" "; } cout<<endl; }
}; int main(){ ArrayQueue <int>*arr=new ArrayQueue<int>(); for(int i=0;i<5;i++){ arr->enqueue(i+1); }
arr->PrintArrayQueue();
cout<<arr->dequeue()<<endl;
cout<<arr->dequeue()<<endl;
arr->PrintArrayQueue();
return 0; }
|
近期评论