标签:
粘个代码功能弱爆,但是还可以用~
用法:定义Queue Q;然后就Q.push(n);Q.pop()……就行了~
1 class Queue 2 { 3 private: 4 int Head,Tail,Size; 5 int val[30010]; 6 7 public: 8 9 Queue() 10 { 11 Head=0; 12 Tail=-1; 13 Size=0; 14 memset(val,0,sizeof(val)); 15 } 16 17 inline bool empty() 18 { 19 return Size==0; 20 } 21 22 inline void push(const int & ele) 23 { 24 Tail=(Tail+1)%30000; 25 Size++; 26 val[Tail]=ele; 27 return ; 28 } 29 30 inline void pop() 31 { 32 if(Size==0)return ; 33 Head=(Head+1)%30000; 34 Size--; 35 return ; 36 } 37 38 inline int front() 39 { 40 if(Size==0)return 0; 41 return val[Head]; 42 } 43 44 inline int back() 45 { 46 if(Size==0)return 0; 47 return val[Tail]; 48 } 49 50 inline int size() 51 { 52 return Size; 53 } 54 55 inline void clear() 56 { 57 Head=0; 58 Tail=-1; 59 Size=0; 60 memset(val,0,sizeof(val)); 61 return ; 62 } 63 }Q;
标签:
原文地址:http://www.cnblogs.com/Gster/p/4703120.html