在 STL 中实现 Multiset 的 C++ 程序
多重集是一种关联容器,其中多个元素可以具有相同的值。
功能及说明:
Functions are used here: ms.size() = Returns the size of multiset. ms.insert) = It is used to insert elements to the multiset. ms.erase() = Removes the value from the multiset. ms.find() = Returns an iterator to the search element in the multiset if found, else returns the iterator to end. ms.count() = Returns the number of matches element in the multiset. ms.begin() = Returns an iterator to the first element in the multiset. ms.end() = Returns an iterator to the last element in the multiset
示例代码
#include#include #include #include using namespace std; int main() { multiset ms; multiset ::iterator it, it1; int c, i; while (1) { cout<<"1.Size of the Multiset"< >c; switch(c) { case 1: cout<<"多重集的大小: "< >i; if (ms.empty()) it1 = ms.insert(i); else it1 = ms.insert(it1, i); break; case 3: cout<<"输入要删除的值: "; cin>>i; ms.erase(i); break; case 4: cout<<"输入要查找的元素 "; cin>>i; it = ms.find(i); if (it != ms.end()) cout<<"Element found"< >i; cout<输出结果 1.Size of the Multiset 2.Insert Element into the Multiset 3.Delete Element from the Multiset 4.Find Element in a Multiset 5.Count Elements with a specific key 6.Display Multiset 7.Exit 输入您的选择: 1 多重集的大小: 0 1.Size of the Multiset 2.Insert Element into the Multiset 3.Delete Element from the Multiset 4.Find Element in a Multiset 5.Count Elements with a specific key 6.Display Multiset 7.Exit 输入您的选择: 2 输入要插入的值: 1 1.Size of the Multiset 2.Insert Element into the Multiset 3.Delete Element from the Multiset 4.Find Element in a Multiset 5.Count Elements with a specific key 6.Display Multiset 7.Exit 输入您的选择: 2 输入要插入的值: 2 1.Size of the Multiset 2.Insert Element into the Multiset 3.Delete Element from the Multiset 4.Find Element in a Multiset 5.Count Elements with a specific key 6.Display Multiset 7.Exit 输入您的选择: 2 输入要插入的值: 3 1.Size of the Multiset 2.Insert Element into the Multiset 3.Delete Element from the Multiset 4.Find Element in a Multiset 5.Count Elements with a specific key 6.Display Multiset 7.Exit 输入您的选择: 2 输入要插入的值: 4 1.Size of the Multiset 2.Insert Element into the Multiset 3.Delete Element from the Multiset 4.Find Element in a Multiset 5.Count Elements with a specific key 6.Display Multiset 7.Exit 输入您的选择: 6 Multiset的元素: 1 2 3 4 1.Size of the Multiset 2.Insert Element into the Multiset 3.Delete Element from the Multiset 4.Find Element in a Multiset 5.Count Elements with a specific key 6.Display Multiset 7.Exit 输入您的选择: 3 输入要删除的值: 4 1.Size of the Multiset 2.Insert Element into the Multiset 3.Delete Element from the Multiset 4.Find Element in a Multiset 5.Count Elements with a specific key 6.Display Multiset 7.Exit 输入您的选择: 4 输入要查找的元素 1 Element found 1.Size of the Multiset 2.Insert Element into the Multiset 3.Delete Element from the Multiset 4.Find Element in a Multiset 5.Count Elements with a specific key 6.Display Multiset 7.Exit 输入您的选择: 5 输入要计算的元素: 2 2 appears 1 times. 1.Size of the Multiset 2.Insert Element into the Multiset 3.Delete Element from the Multiset 4.Find Element in a Multiset 5.Count Elements with a specific key 6.Display Multiset 7.Exit 输入您的选择: 7 Exit code: 1
热门推荐
1 训练狗狗憋尿
2 狗狗追踪训练
3 狗狗训练要多少钱
5 深圳狗狗训练
6 训练狗狗唤回
7 狗狗叫怎么训练
8 狗狗训练班
10 狗狗社会化训练
11 狗狗叫回训练
12 广州狗狗训练学校
13 狗狗训练躺下
14 狗狗随行训练
15 训练狗狗巡回
16 狗狗要怎么训练
17 狗狗喂食训练
18 训练狗狗躺下