C++ 隊列模板 Queue

來源:互聯網
上載者:User

標籤:

粘個代碼功能弱爆,但是還可以用~

用法:定義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;

 

C++ 隊列模板 Queue

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.