本文整理汇总了C++中Treap::Insert方法的典型用法代码示例。如果您正苦于以下问题:C++ Treap::Insert方法的具体用法?C++ Treap::Insert怎么用?C++ Treap::Insert使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Treap
的用法示例。
在下文中一共展示了Treap::Insert方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: treap
void treap()
{
Treap<int> treap;
#define TREAP_LOOP for (int i = 0; i < 1000; i ++)
TREAP_LOOP
{
treap.Insert(i);
assert(treap.GetMin() == 0);
assert(treap.GetMax() == i);
}
std::cout<<"Treap constructed"<<std::endl;
// print keys in sorted order
treap.InOrderTraversal();
TREAP_LOOP
{
assert(treap.Exists(i));
}
TREAP_LOOP
{
treap.Delete(i);
}
TREAP_LOOP
{
assert(!treap.Exists(i));
}
}
示例2: Treap
TEST(Treap , Min)
{
Treap* tr = new Treap(false);
tr->Insert(1);
tr->Insert(5);
tr->Insert(2);
tr->Insert(61);
tr->Insert(61);
tr->Insert(24);
tr->Insert(51);
tr->Insert(61);
tr->Insert(57);
tr->Insert(32);
tr->Insert(24);
CHECK(tr->Min() == 1);
tr->Remove(1);
tr->Remove(2);
CHECK(tr->Min() == 5);
tr->Remove(5);
CHECK(tr->Min() == 24);
tr->Remove(24);
CHECK(tr->Min() == 32);
tr->Remove(32);
CHECK(tr->Min() == 51);
tr->Remove(51);
CHECK(tr->Min() == 57);
tr->Remove(57);
CHECK(tr->Min() == 61);
tr->Remove(61);
CHECK(tr->Min() == -1);
delete tr;
}
示例3: main
int main()
{
freopen("Text/ORDERSET.txt","r",stdin);
int Q; scanf("%d",&Q);
Treap oTreap;
while(Q--)
{
char t[5];
int p;
scanf("%s%d",t,&p);
if(t[0]=='I')
{
oTreap.Insert(p);
}
else if(t[0]=='D')
{
oTreap.Delete(p);
}
else if(t[0]=='K')
{
int v = oTreap.FindKth(p);
if(v > -INF)
{
printf("%d\n",v);
}
else
puts("invalid");
}
else
{
int v = oTreap.Count(p);
printf("%d\n",v);
}
}
return 0;
}