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中,队列是遵循FIFO ( 先进先出 )元素排列的一种容器,即,首先插入的元素将被首先删除。 在队列中,元素被插入称为“ back”的一端,并从称为“ front”的另一端删除。
1)C ++ STL queue :: empty()函数 (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()函数检查队列是否为空队列,如果队列为空即具有0个元素,则该函数返回1(true),如果队列不为空,则该函数返回0(false)。
Syntax:
句法:
queue_name.empty()
Parameters(s): None
参数:无
Return type:
返回类型:
Returns 1, if queue is empty
如果队列为空,则返回1
Returns 0, if queue is not empty
如果队列不为空,则返回0
Program:
程序:
#include <iostream>
#include <queue>
using namespace std;
//Main fubction
int main()
{
// declaring two queues
queue<int> Q1;
queue<int> Q2;
//inserting elements to Q1
Q1.push(10);
Q1.push(20);
Q1.push(30);
//checking
if(Q1.empty())
cout<<"Q1 is an empty queue"<<endl;
else
cout<<"Q1 is not an empty queue"<<endl;
if(Q2.empty())
cout<<"Q2 is an empty queue"<<endl;
else
cout<<"Q2 is not an empty queue"<<endl;
return 0;
}
Output
输出量
Q1 is not an empty queue
Q2 is an empty queue
2)C ++ STL queue :: size()函数 (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()返回队列中元素的总数,或者可以说它返回队列的大小。
Syntax:
句法:
queue_name.size()
Parameter(s): None
参数:无
Return: total number of elements/size of the queue
返回:元素总数/队列大小
Program:
程序:
#include <iostream>
#include <queue>
using namespace std;
//Main fubction
int main()
{
// declaring two queues
queue<int> Q1;
queue<int> Q2;
//inserting elements to Q1
Q1.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 源码