Sticky code function of weak explosion, but also can use ~
Usage: Define queue Q; then Q.push (n); Q.pop () ... On the line ~
1 classQueue2 {3 Private:4 inthead,tail,size;5 intval[30010];6 7 Public:8 9 Queue ()Ten { OneHead=0; Atail=-1; -Size=0; -Memset (Val,0,sizeof(Val)); the } - -InlineBOOLempty () - { + returnsize==0; - } + AInlinevoidPushConst int&ele) at { -Tail= (tail+1)%30000; -size++; -val[tail]=ele; - return ; - } in -Inlinevoidpop () to { + if(size==0)return ; -Head= (head+1)%30000; thesize--; * return ; $ }Panax Notoginseng -InlineintFront () the { + if(size==0)return 0; A returnVal[head]; the } + -InlineintBack () $ { $ if(size==0)return 0; - returnVal[tail]; - } the -Inlineintsize ()Wuyi { the returnSize; - } Wu -InlinevoidClear () About { $Head=0; -tail=-1; -Size=0; -Memset (Val,0,sizeof(Val)); A return ; + } the}q;
C + + Queue template queue