-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsettest.cpp
More file actions
43 lines (31 loc) · 734 Bytes
/
Copy pathsettest.cpp
File metadata and controls
43 lines (31 loc) · 734 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#include <iostream>
#include <set>
using namespace std;
int main()
{
// default sort by ascending order
set<string> cars = {"Volvo", "BMW", "Ford", "Mazda"};
for (string car : cars)
{
cout << car << "\n";
}
// Sort elements in a set in descending order
set<int, greater<int>> numbers = {1, 7, 3, 2, 5, 9};
// Print the elements
for (int num : numbers)
{
cout << num << "\n";
}
cars.insert("Tesla");
cars.insert("VW");
cars.insert("Toyota");
cars.insert("Audi");
// Remove elements
cars.erase("Volvo");
cars.erase("Mazda");
// Remove all elements
cars.clear();
cout << cars.size();
cout << cars.empty();
return 0;
}