Rust's ordered set is a BTreeSet
:
use std::collections::BTreeSet; // Type inference lets us omit an explicit type signature (which // would be `BTreeSet<&str>` in this example). let mut books = BTreeSet::new(); // Add some books. books.insert("A Dance With Dragons"); books.insert("To Kill a Mockingbird"); books.insert("The Odyssey"); books.insert("The Great Gatsby");
An ordered map is a BTreeMap
.
Since the set and map are ordered, there should be a way to get the maximal and minimal element contained. How do you get them?
BinaryHeap
instead, which has apop()
method. – Ahopeek
if you only need to read the value. But I am not sure you can also get the other extremal value. In my personal case, I was usingBTreeMap
s and the order was used to search inside the collection. – Chirpy