#include <iostream>
#include <vector>
#include <queue>
using namespace std;
template <typename T>
class LeftlistNode
{
public:
T key;
int npl;
LeftlistNode* left;
LeftlistNode* right; LeftlistNode(T& value, LeftlistNode* l = NULL, LeftlistNode* r = NULL, int n = ):
key(value), left(l), right(r), npl(n){}
}; template <typename T>
class LeftlistHeap{
private:
LeftlistNode<T>* mRoot;
public:
LeftlistHeap(){}
LeftlistHeap(vector<T>& items){
mRoot = buildHeap(items);
}
~LeftlistHeap(){
destory(mRoot);
}
void merge(LeftlistHeap<T>* other){
if(this == other)
return;
mRoot = _merge(mRoot, other->mRoot);
}
void insert(T& key){
mRoot = _merge(mRoot, new LeftlistNode<T>(key));
}
void remove(){
LeftlistNode<T> old = mRoot;
mRoot = _merge(mRoot->Left, mRoot->right);
delete old;
}
T get_min(){
return mRoot->key;
} void destory(LeftlistNode<T>* & mRoot){
if(mRoot == NULL)
return;
if(mRoot->left != NULL)
destory(mRoot->left);
if(mRoot->right != NULL)
destory(mRoot->right);
delete mRoot;
} private:
LeftlistNode<T>* _merge1(LeftlistNode<T>* x, LeftlistNode<T>* y){
if(x == NULL)
return y;
if(y == NULL)
return x;
if(x->key < y->key)
_merge2(x, y);
else
_merge2(y, x);
}
LeftlistNode<T>* _merge2(LeftlistNode<T>* x, LeftlistNode<T>* y){
if(x->left == NULL)
x->left = y;
else{
x->right = _merge1(x->right, y);
if(x->left->npl < x->right->npl){
LeftlistNode<T>* temp = x->left;
x->left = x->right;
x->right = temp;
}
x->npl = x->right->npl + ;
}
return x;
} LeftlistNode<T>* _merge(LeftlistNode<T>* x, LeftlistNode<T>* y){
if(x == NULL && y == NULL)
return NULL;
else if(x == NULL && y != NULL)
return y;
else if(y == NULL && x != NULL)
return x;
else{
if(x->key > y->key){
LeftlistNode<T>* tmp = x;
x = y;
y = tmp;
}
if(x->left == NULL)
x->left = y;
else{
x->right = _merge(x->right, y);
if(x->left->npl < x->right->npl){
LeftlistNode<T>* tmp = x->left;
x->left = x->right;
x->right = tmp;
}
x->npl = x->right->npl + ;
}
}
return x;
}
LeftlistNode<T>* buildHeap(vector<T>& items){
queue<LeftlistNode<T>*> tmp_queue;
for(int i = ; i < items.size(); ++i)
tmp_queue.push(new LeftlistNode<T>(items[i]));
while(tmp_queue.size() > ){
LeftlistNode<T>* t1 = tmp_queue.front();
tmp_queue.pop();
LeftlistNode<T>* t2 = tmp_queue.front();
tmp_queue.pop();
tmp_queue.push(_merge1(t1, t2));
}
return tmp_queue.front();
} }; int main(){
int a[]= {,,,,,,,};
vector<int> lt(a, a + );
LeftlistHeap<int> yj(lt);
cout << yj.get_min() << endl;
return ;
}