A queue is a linear population that can only add elements to one side and delete elements from the other end
Loop queue
- In the imagined array is bent into a ring, when the element is out of the queue, the successor element does not move, and each time the end of the queue reaches the last element of the array, it goes back to the beginning of the array.
Queue class Template
//Queue.h#ifndef Queue_h#defineQueue_h#include<cassert>//definition of a class templateTemplate <classTintSIZE = ->classqueue{Private: intfront, rear, count; T List[size]; Public: Queue (); voidInsertConstT &item); T Remove (); voidClear (); ConstT &getfront ()Const; intGetLength ()Const; BOOLIsEmpty ()Const; BOOLIsfull ()Const;}; Template<classTintSize> queue<t, Size>::queue (): Front (0), Rear (0), COUNT (0) {}template<classTintSize>voidQueue<t, Size>::insert (Constt&Item) {Assert (Count!=SIZE); Count++; List[rear]=item; Rear= (Rear +1) %SIZE;} Template<classTintSize> T queue<t, size>:: Remove () {Assert (Count!=0); inttemp =Front; Count--; Front= (front +1) %SIZE; returnlist[temp];} Template<classTintSize>ConstT &queue<t, Size>::getfront ()Const{ returnList[front];} Template<classTintSize>intQueue<t, Size>::getlength ()Const{ returncount;} Template<classTintSize>BOOLQueue<t, Size>::isempty ()Const{ returnCount = =0;} Template<classTintSize>BOOLQueue<t, Size>::isfull ()Const{ returnCount = =SIZE;} Template<classTintSize>BOOLQueue<t, size>:: Clear () {count=0; Front=0; Rear=0;}#endif //
C + + Learning Note 50: Queue class templates