Architecture Diagram
MULTISET ORDERED SEQUENCE:
[ 10 ] ──► [ 20 ] ──► [ 20 ] ──► [ 20 ] ──► [ 30 ] ──► [ 40 ]MULTISET ORDERED SEQUENCE:
[ 10 ] ──► [ 20 ] ──► [ 20 ] ──► [ 20 ] ──► [ 30 ] ──► [ 40 ]ms.erase(20): Deletes ALL three 20s!ms.erase(ms.find(20)): Deletes ONLY the first 20 found.#include <iostream>
#include <set>
int main() {
std::multiset<int> scores = {90, 75, 90, 85, 90, 60};
std::cout << "All Scores (Multiset): ";
for (int s : scores) std::cout << s << " ";
std::cout << "\n";
std::cout << "Count of 90s: " << scores.count(90) << "\n";
// 1. Remove ONLY ONE occurrence of 90
auto it = scores.find(90);
if (it != scores.end()) {
scores.erase(it); // Erase by iterator removes 1 item
}
std::cout << "After erasing single 90: ";
for (int s : scores) std::cout << s << " ";
std::cout << "\n";
// 2. Remove ALL occurrences of remaining 90s
scores.erase(90); // Erase by value removes all
std::cout << "After erasing all 90s: ";
for (int s : scores) std::cout << s << " ";
std::cout << "\n";
return 0;
}ms.erase(ms.find(val)) if your intention is to remove only a single instance.std::multiset for tracking dynamic sliding-window medians and frequency counters..equal_range(val) to iterate over all duplicates of a specific value efficiently.