Skip to content

Commit

Permalink
Create ordered_set.cpp
Browse files Browse the repository at this point in the history
  • Loading branch information
wisdompeak authored Nov 9, 2020
1 parent 806c27d commit 9484224
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions Template/RB_Tree/ordered_set.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
using namespace __gnu_pbds;

typedef tree<
int ,
null_type,
less<int>,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;

int main() {
ordered_set Set;
vector<int>nums({1,3,2,2,4,4,8,6,7,3});
for (int i=0; i<nums.size(); i++)
{
Set.insert(nums[i]);
cout<<nums[i]<<":"<<Set.order_of_key(nums[i])<<endl;
}
}
// If you want to make it like a multiset, you may design the base type of the ordered_set as pair<int,int>

0 comments on commit 9484224

Please sign in to comment.