stl:queue 源码_C ++ STL中的queue :: empty()和queue :: size()
stl:queue 源碼
In C++ STL, Queue is a type of container that follows FIFO (First-in-First-out) elements arrangement i.e. the elements which inserts first will be removed first. In queue, elements are inserted at one end known as "back" and are deleted from another end known as "front".
在C ++ STL中,隊(duì)列是遵循FIFO ( 先進(jìn)先出 )元素排列的一種容器,即,首先插入的元素將被首先刪除。 在隊(duì)列中,元素被插入稱為“ back”的一端,并從稱為“ front”的另一端刪除。
1)C ++ STL queue :: empty()函數(shù) (1) C++ STL queue::empty() function)
empty() function checks weather a queue is an empty queue or not, if a queue is empty i.e. it has 0 elements, the function returns 1 (true) and if queue is not empty, the function returns 0 (false).
empty()函數(shù)檢查隊(duì)列是否為空隊(duì)列,如果隊(duì)列為空即具有0個(gè)元素,則該函數(shù)返回1(true),如果隊(duì)列不為空,則該函數(shù)返回0(false)。
Syntax:
句法:
queue_name.empty()Parameters(s): None
參數(shù):無
Return type:
返回類型:
Returns 1, if queue is empty
如果隊(duì)列為空,則返回1
Returns 0, if queue is not empty
如果隊(duì)列不為空,則返回0
Program:
程序:
#include <iostream> #include <queue> using namespace std;//Main fubction int main() {// declaring two queuesqueue<int> Q1;queue<int> Q2;//inserting elements to Q1Q1.push(10);Q1.push(20);Q1.push(30);//checking if(Q1.empty())cout<<"Q1 is an empty queue"<<endl;elsecout<<"Q1 is not an empty queue"<<endl;if(Q2.empty())cout<<"Q2 is an empty queue"<<endl;elsecout<<"Q2 is not an empty queue"<<endl;return 0; }Output
輸出量
Q1 is not an empty queue Q2 is an empty queue .minHeight{min-height: 250px;}@media (min-width: 1025px){.minHeight{min-height: 90px;}} .minHeight{min-height: 250px;}@media (min-width: 1025px){.minHeight{min-height: 90px;}}2)C ++ STL queue :: size()函數(shù) (2) C++ STL queue::size() function)
size() returns the total number of elements of a queue or we can say it returns the size of a queue.
size()返回隊(duì)列中元素的總數(shù),或者可以說它返回隊(duì)列的大小。
Syntax:
句法:
queue_name.size()Parameter(s): None
參數(shù):無
Return: total number of elements/size of the queue
返回:元素總數(shù)/隊(duì)列大小
Program:
程序:
#include <iostream> #include <queue> using namespace std;//Main fubction int main() {// declaring two queuesqueue<int> Q1;queue<int> Q2;//inserting elements to Q1Q1.push(10);Q1.push(20);Q1.push(30);cout<<"size of Q1: "<<Q1.size()<<endl;cout<<"size of Q2: "<<Q2.size()<<endl;return 0; }Output
輸出量
size of Q1: 3 size of Q2: 0翻譯自: https://www.includehelp.com/stl/queue-empty-and-queue-size.aspx
stl:queue 源碼
創(chuàng)作挑戰(zhàn)賽新人創(chuàng)作獎(jiǎng)勵(lì)來咯,堅(jiān)持創(chuàng)作打卡瓜分現(xiàn)金大獎(jiǎng)總結(jié)
以上是生活随笔為你收集整理的stl:queue 源码_C ++ STL中的queue :: empty()和queue :: size()的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: strtoupper 小写_PHP st
- 下一篇: ruby hash方法_Ruby中带有示