create set main and ds set main

This commit is contained in:
Jidong Xiao
2025-03-20 23:59:15 -04:00
committed by JamesFlare
parent fb81b68821
commit 956d3892da
5 changed files with 34 additions and 479 deletions

View File

@@ -0,0 +1,31 @@
#include <iostream>
#include <set>
int main() {
// create a set of integers
std::set<int> numbers;
// insert some values into the set
numbers.insert(10);
numbers.insert(5);
numbers.insert(20);
numbers.insert(15);
numbers.insert(5); // duplicate value (won't be inserted)
// print the elements of the set
std::cout << "The elements in the set are:" << std::endl;
for (int num : numbers) {
std::cout << num << " ";
}
std::cout << std::endl;
// check if a specific value exists in the set
int value = 15;
if (numbers.find(value) != numbers.end()) {
std::cout << value << " is found in the set." << std::endl;
} else {
std::cout << value << " is not found in the set." << std::endl;
}
return 0;
}