如下。
#ifndef CONTAINER_H
#define CONTAINER_H
#include "BasicContainer.h"
#include <algorithm>
#include <vector>
#include <set>
using namespace std;
template<class A, class C>
class Container : public BasicContainer<A>
{
C base;
public:
void insert(const A &x)
{
for(auto t = base.begin(); t != base.end(); ++t)
if(*t > x)
{
base.insert(t, x);
return;
}
base.insert(base.end(), x);
}
A find(int k)
{
auto t = base.begin();
while(--k)
++t;
return *t;
}
};
template<class A>
class Container<A, vector<A>>: public BasicContainer<A>{
vector<A> base;
bool isSorted = false;
public:
void insert(const A &x){
isSorted = false;
base.push_back(x);
}
A find(int k){
if(!isSorted){
sort(base.begin(),base.end());
isSorted = true;
}
return *(base.begin()+k-1);
}
};
template<class A>
class Container<A, multiset<A>>: public BasicContainer<A>{
multiset<A> base;
public:
void insert(const A &x){
base.insert(x);
}
A find(int k){
auto iter=base.begin();
for (int i=0; i<k-1; i++) {
iter++;
}
return *iter;
}
};
#endif