forward_list :: max_size()是C++ STL中的内置函数,该函数返回forward_list容器可以容纳的最大元素数
句法:
forward_list_name.max_size()
参数:该函数不接受任何参数。
返回值:该函数返回容器可以容纳的最大元素数。
下面的程序说明了上述函数:
程序1:
// CPP program to demonstrate the
// forward_list::max_size() function
// when the list is not-empty
#include
using namespace std;
int main()
{
// declaration of forward list
forward_list fl;
// assign value
fl.assign(5, 8);
// prints the elements
cout << "The forward_list elements: ";
for (auto it = fl.begin(); it != fl.end(); it++)
cout << *it << " ";
cout << "\nThe max size: " << fl.max_size();
return 0;
}
输出:
The forward_list elements: 8 8 8 8 8
The max size: 1152921504606846975
程序1:
// CPP program to demonstrate the
// forward_list::max_size() function
// when the list is empty
#include
using namespace std;
int main()
{
// declaration of forward list
forward_list fl;
cout << "\nThe max size: " << fl.max_size();
return 0;
}
输出:
The max size: 1152921504606846975
要从最佳影片策划和实践问题去学习,检查了C++基础课程为基础,以先进的C++和C++ STL课程基础加上STL。要完成从学习语言到DS Algo等的更多准备工作,请参阅“完整面试准备课程” 。