C++ STL中的多集Max()

这个 多集::最大大小() 在C++ STL中是一个内置函数,它返回多集容器可以容纳的最大元素数。

null

语法:

multiset_name.max_size()

参数: 该函数不接受任何参数。

返回值: 该函数返回多集容器可以容纳的最大元素数。

以下程序说明了上述功能:

项目1:

// CPP program to demonstrate the
// multiset::max_size() function
// when multiset is non-empty
#include <bits/stdc++.h>
using namespace std;
int main()
{
multiset< int > s;
// Function to insert elements
// in the multiset container
s.insert(10);
s.insert(13);
s.insert(13);
s.insert(25);
s.insert(24);
cout << "The multiset elements are: " ;
for ( auto it = s.begin(); it != s.end(); it++)
cout << *it << " " ;
cout << "The max size of multiset: " << s.max_size();
return 0;
}


输出:

The multiset elements are: 10 13 13 24 25 
The max size of multiset: 461168601842738790

项目2:

// CPP program to demonstrate the
// multiset::max_size() function
// when multiset is empty
#include <bits/stdc++.h>
using namespace std;
int main()
{
multiset< int > s;
cout << "The max size of multiset: " << s.max_size();
return 0;
}


输出:

The max size of multiset: 461168601842738790

多重集的所有函数

© 版权声明
THE END
喜欢就支持一下吧
点赞6 分享