stl_rb_tree.cpp
This commit is contained in:
43
cpp/stl_rb_tree.cpp
Normal file
43
cpp/stl_rb_tree.cpp
Normal file
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
VIM: let b:cf5build="clang -std=c++20 -O2 -pthread -lstdc++ -I. {SRC} -o {OUT}"
|
||||
VIM: let b:cf5run="{OUT}"
|
||||
*/
|
||||
#include <iostream>
|
||||
#include <exception>
|
||||
#include <chrono>
|
||||
#include <set>
|
||||
|
||||
int main ( void )
|
||||
{try{
|
||||
auto begin = std::chrono::high_resolution_clock::now();
|
||||
|
||||
std::set<int> s({1, 2, 3, 4, 5});
|
||||
//......
|
||||
auto it = s.begin();
|
||||
for (int i = 0; i < 10; i++){
|
||||
std::cout << *it++ << ", " << std::endl;
|
||||
}
|
||||
std::cout << "-------" << std::endl;
|
||||
it = s.end();
|
||||
for (int i = 0; i < 10; i++){
|
||||
std::cout << *it-- << ", " << std::endl;
|
||||
}
|
||||
|
||||
auto end = std::chrono::high_resolution_clock::now();
|
||||
std::chrono::duration<double> seconds = end - begin;
|
||||
std::cout << "Time: " << seconds.count() << std::endl;
|
||||
return 0;
|
||||
}
|
||||
catch ( const std::exception& e )
|
||||
{
|
||||
std::cerr << std::endl
|
||||
<< "std::exception(\"" << e.what() << "\")." << std::endl;
|
||||
return 2;
|
||||
}
|
||||
catch ( ... )
|
||||
{
|
||||
std::cerr << std::endl
|
||||
<< "unknown exception." << std::endl;
|
||||
return 1;
|
||||
}}
|
||||
|
||||
Reference in New Issue
Block a user