ในบทช่วยสอนนี้ เราจะพูดถึงโปรแกรมเพื่อทำความเข้าใจ multiset max_size() ใน C++ STL
ฟังก์ชัน max_size() จะคืนค่าจำนวนองค์ประกอบสูงสุดที่คอนเทนเนอร์สามารถเก็บได้
ตัวอย่าง
#include <bits/stdc++.h>
using namespace std;
int main(){
multiset<int> s;
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 << "\nThe max size of multiset: " << s.max_size();
return 0;
} ผลลัพธ์
The multiset elements are: 10 13 13 24 25 The max size of multiset: 461168601842738790